Skip to content

Fix FirebaseApp overwriting FirebaseError name field #1911

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions packages/app/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ export const enum AppError {

const ERRORS: ErrorMap<AppError> = {
[AppError.NO_APP]:
"No Firebase App '{$name}' has been created - " +
"No Firebase App '{$appName}' has been created - " +
'call Firebase App.initializeApp()',
[AppError.BAD_APP_NAME]: "Illegal App name: '{$name}",
[AppError.DUPLICATE_APP]: "Firebase App named '{$name}' already exists",
[AppError.APP_DELETED]: "Firebase App named '{$name}' already deleted",
[AppError.BAD_APP_NAME]: "Illegal App name: '{$appName}",
[AppError.DUPLICATE_APP]: "Firebase App named '{$appName}' already exists",
[AppError.APP_DELETED]: "Firebase App named '{$appName}' already deleted",
[AppError.DUPLICATE_SERVICE]:
"Firebase service named '{$name}' already registered",
"Firebase service named '{$appName}' already registered",
[AppError.INVALID_APP_ARGUMENT]:
'firebase.{$name}() takes either no argument or a ' +
'firebase.{$appName}() takes either no argument or a ' +
'Firebase App instance.'
};

type ErrorParams = { [key in AppError]: { name: string } };
type ErrorParams = { [key in AppError]: { appName: string } };

export const ERROR_FACTORY = new ErrorFactory<AppError, ErrorParams>(
'app',
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/firebaseApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export class FirebaseAppImpl implements FirebaseApp {
*/
private checkDestroyed_(): void {
if (this.isDeleted_) {
throw ERROR_FACTORY.create(AppError.APP_DELETED, { name: this.name_ });
throw ERROR_FACTORY.create(AppError.APP_DELETED, { appName: this.name_ });
}
}
}
Expand Down
12 changes: 7 additions & 5 deletions packages/app/src/firebaseNamespaceCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export function createFirebaseNamespaceCore(
function app(name?: string): FirebaseApp {
name = name || DEFAULT_ENTRY_NAME;
if (!contains(apps, name)) {
throw ERROR_FACTORY.create(AppError.NO_APP, { name });
throw ERROR_FACTORY.create(AppError.NO_APP, { appName: name });
}
return apps[name];
}
Expand Down Expand Up @@ -137,11 +137,13 @@ export function createFirebaseNamespaceCore(
const { name } = config;

if (typeof name !== 'string' || !name) {
throw ERROR_FACTORY.create(AppError.BAD_APP_NAME, { name: String(name) });
throw ERROR_FACTORY.create(AppError.BAD_APP_NAME, {
appName: String(name)
});
}

if (contains(apps, name)) {
throw ERROR_FACTORY.create(AppError.DUPLICATE_APP, { name });
throw ERROR_FACTORY.create(AppError.DUPLICATE_APP, { appName: name });
}

const app = new firebaseAppImpl(
Expand Down Expand Up @@ -180,7 +182,7 @@ export function createFirebaseNamespaceCore(
): FirebaseServiceNamespace<FirebaseService> {
// Cannot re-register a service that already exists
if (factories[name]) {
throw ERROR_FACTORY.create(AppError.DUPLICATE_SERVICE, { name });
throw ERROR_FACTORY.create(AppError.DUPLICATE_SERVICE, { appName: name });
}

// Capture the service factory for later service instantiation
Expand All @@ -203,7 +205,7 @@ export function createFirebaseNamespaceCore(
// Invalid argument.
// This happens in the following case: firebase.storage('gs:/')
throw ERROR_FACTORY.create(AppError.INVALID_APP_ARGUMENT, {
name
appName: name
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/lite/firebaseAppLite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export class FirebaseAppLiteImpl implements FirebaseApp {
*/
private checkDestroyed_(): void {
if (this.isDeleted_) {
throw ERROR_FACTORY.create(AppError.APP_DELETED, { name: this.name_ });
throw ERROR_FACTORY.create(AppError.APP_DELETED, { appName: this.name_ });
}
}
}