Skip to content

Update error handling for TS v4.4 unknown vars #6335

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 2 commits into from
Jun 8, 2022
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
2 changes: 1 addition & 1 deletion packages/analytics/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function registerAnalytics(): void {
};
} catch (e) {
throw ERROR_FACTORY.create(AnalyticsError.INTEROP_COMPONENT_REG_FAILED, {
reason: e
reason: e as Error
});
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/auth/src/core/auth/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class AuthMiddlewareQueue {
}

throw this.auth._errorFactory.create(
AuthErrorCode.LOGIN_BLOCKED, { originalMessage: e.message });
AuthErrorCode.LOGIN_BLOCKED, { originalMessage: (e as Error)?.message });
}
}
}
}
2 changes: 1 addition & 1 deletion packages/auth/test/integration/flows/phone.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ describe('Integration test: phone auth', () => {
)
);
} catch (e) {
error = e;
error = e as FirebaseError;
}

expect(error!.customData!.phoneNumber).to.eq(PHONE_A.phoneNumber);
Expand Down
62 changes: 47 additions & 15 deletions packages/firestore-compat/src/api/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,15 +297,19 @@ export class Firestore
collection(this._delegate, pathString)
);
} catch (e) {
throw replaceFunctionName(e, 'collection()', 'Firestore.collection()');
throw replaceFunctionName(
e as Error,
'collection()',
'Firestore.collection()'
);
}
}

doc(pathString: string): PublicDocumentReference {
try {
return new DocumentReference(this, doc(this._delegate, pathString));
} catch (e) {
throw replaceFunctionName(e, 'doc()', 'Firestore.doc()');
throw replaceFunctionName(e as Error, 'doc()', 'Firestore.doc()');
}
}

Expand All @@ -314,7 +318,7 @@ export class Firestore
return new Query(this, collectionGroup(this._delegate, collectionId));
} catch (e) {
throw replaceFunctionName(
e,
e as Error,
'collectionGroup()',
'Firestore.collectionGroup()'
);
Expand Down Expand Up @@ -687,7 +691,7 @@ export class DocumentReference<T = PublicDocumentData>
);
} catch (e) {
throw replaceFunctionName(
e,
e as Error,
'collection()',
'DocumentReference.collection()'
);
Expand Down Expand Up @@ -718,7 +722,11 @@ export class DocumentReference<T = PublicDocumentData>
return setDoc(this._delegate, value as WithFieldValue<T>);
}
} catch (e) {
throw replaceFunctionName(e, 'setDoc()', 'DocumentReference.set()');
throw replaceFunctionName(
e as Error,
'setDoc()',
'DocumentReference.set()'
);
}
}

Expand All @@ -745,7 +753,11 @@ export class DocumentReference<T = PublicDocumentData>
);
}
} catch (e) {
throw replaceFunctionName(e, 'updateDoc()', 'DocumentReference.update()');
throw replaceFunctionName(
e as Error,
'updateDoc()',
'DocumentReference.update()'
);
}
}

Expand Down Expand Up @@ -991,7 +1003,11 @@ export class Query<T = PublicDocumentData>
query(this._delegate, where(fieldPath as string, opStr, value))
);
} catch (e) {
throw replaceFunctionName(e, /(orderBy|where)\(\)/, 'Query.$1()');
throw replaceFunctionName(
e as Error,
/(orderBy|where)\(\)/,
'Query.$1()'
);
}
}

Expand All @@ -1008,15 +1024,19 @@ export class Query<T = PublicDocumentData>
query(this._delegate, orderBy(fieldPath as string, directionStr))
);
} catch (e) {
throw replaceFunctionName(e, /(orderBy|where)\(\)/, 'Query.$1()');
throw replaceFunctionName(
e as Error,
/(orderBy|where)\(\)/,
'Query.$1()'
);
}
}

limit(n: number): Query<T> {
try {
return new Query<T>(this.firestore, query(this._delegate, limit(n)));
} catch (e) {
throw replaceFunctionName(e, 'limit()', 'Query.limit()');
throw replaceFunctionName(e as Error, 'limit()', 'Query.limit()');
}
}

Expand All @@ -1027,15 +1047,19 @@ export class Query<T = PublicDocumentData>
query(this._delegate, limitToLast(n))
);
} catch (e) {
throw replaceFunctionName(e, 'limitToLast()', 'Query.limitToLast()');
throw replaceFunctionName(
e as Error,
'limitToLast()',
'Query.limitToLast()'
);
}
}

startAt(...args: any[]): Query<T> {
try {
return new Query(this.firestore, query(this._delegate, startAt(...args)));
} catch (e) {
throw replaceFunctionName(e, 'startAt()', 'Query.startAt()');
throw replaceFunctionName(e as Error, 'startAt()', 'Query.startAt()');
}
}

Expand All @@ -1046,7 +1070,11 @@ export class Query<T = PublicDocumentData>
query(this._delegate, startAfter(...args))
);
} catch (e) {
throw replaceFunctionName(e, 'startAfter()', 'Query.startAfter()');
throw replaceFunctionName(
e as Error,
'startAfter()',
'Query.startAfter()'
);
}
}

Expand All @@ -1057,15 +1085,15 @@ export class Query<T = PublicDocumentData>
query(this._delegate, endBefore(...args))
);
} catch (e) {
throw replaceFunctionName(e, 'endBefore()', 'Query.endBefore()');
throw replaceFunctionName(e as Error, 'endBefore()', 'Query.endBefore()');
}
}

endAt(...args: any[]): Query<T> {
try {
return new Query(this.firestore, query(this._delegate, endAt(...args)));
} catch (e) {
throw replaceFunctionName(e, 'endAt()', 'Query.endAt()');
throw replaceFunctionName(e as Error, 'endAt()', 'Query.endAt()');
}
}

Expand Down Expand Up @@ -1265,7 +1293,11 @@ export class CollectionReference<T = PublicDocumentData>
);
}
} catch (e) {
throw replaceFunctionName(e, 'doc()', 'CollectionReference.doc()');
throw replaceFunctionName(
e as Error,
'doc()',
'CollectionReference.doc()'
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/firestore/src/core/event_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export async function eventManagerListen(
queryInfo.viewSnap = await eventManagerImpl.onListen(query);
} catch (e) {
const firestoreError = wrapInUserErrorIfRecoverable(
e,
e as Error,
`Initialization of query '${stringifyQuery(listener.query)}' failed`
);
listener.onError(firestoreError);
Expand Down
2 changes: 1 addition & 1 deletion packages/messaging/src/helpers/registerDefaultSw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export async function registerDefaultSw(
});
} catch (e) {
throw ERROR_FACTORY.create(ErrorCode.FAILED_DEFAULT_REGISTRATION, {
browserErrorMessage: e.message
browserErrorMessage: (e as Error)?.message
});
}
}
8 changes: 5 additions & 3 deletions repo-scripts/api-documenter/src/plugin/PluginLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ export class PluginLoader {
);
} catch (e) {
throw new Error(
`Failed to construct feature subclass:\n` + e.toString()
`Failed to construct feature subclass:\n` +
(e as Error)?.toString()
);
}
if (
Expand All @@ -140,7 +141,7 @@ export class PluginLoader {
} catch (e) {
throw new Error(
'Error occurred during the onInitialized() event: ' +
e.toString()
(e as Error)?.toString()
);
}

Expand All @@ -153,7 +154,8 @@ export class PluginLoader {
}
} catch (e) {
throw new Error(
`Error loading plugin ${configPlugin.packageName}: ` + e.message
`Error loading plugin ${configPlugin.packageName}: ` +
(e as Error)?.message
);
}
}
Expand Down
5 changes: 3 additions & 2 deletions scripts/ci/check_changeset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,11 @@ async function main() {
await exec(`yarn changeset status`);
console.log(`::set-output name=BLOCKING_FAILURE::false`);
} catch (e) {
if (e.message.match('No changesets present')) {
const error = e as Error;
if (error.message.match('No changesets present')) {
console.log(`::set-output name=BLOCKING_FAILURE::false`);
} else {
const messageLines = e.message.replace(/🦋 error /g, '').split('\n');
const messageLines = error.message.replace(/🦋 error /g, '').split('\n');
let formattedStatusError =
'- Changeset formatting error in following file:%0A';
formattedStatusError += ' ```%0A';
Expand Down