Skip to content

Commit 8340f84

Browse files
authored
Update error handling for TS v4.4 unknown vars (#6335)
* Update error handling for TS v4.4 unknown vars * Update formatting
1 parent 497d34c commit 8340f84

File tree

8 files changed

+61
-26
lines changed

8 files changed

+61
-26
lines changed

packages/analytics/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function registerAnalytics(): void {
8282
};
8383
} catch (e) {
8484
throw ERROR_FACTORY.create(AnalyticsError.INTEROP_COMPONENT_REG_FAILED, {
85-
reason: e
85+
reason: e as Error
8686
});
8787
}
8888
}

packages/auth/src/core/auth/middleware.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export class AuthMiddlewareQueue {
8787
}
8888

8989
throw this.auth._errorFactory.create(
90-
AuthErrorCode.LOGIN_BLOCKED, { originalMessage: e.message });
90+
AuthErrorCode.LOGIN_BLOCKED, { originalMessage: (e as Error)?.message });
9191
}
9292
}
93-
}
93+
}

packages/auth/test/integration/flows/phone.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ describe('Integration test: phone auth', () => {
294294
)
295295
);
296296
} catch (e) {
297-
error = e;
297+
error = e as FirebaseError;
298298
}
299299

300300
expect(error!.customData!.phoneNumber).to.eq(PHONE_A.phoneNumber);

packages/firestore-compat/src/api/database.ts

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -297,15 +297,19 @@ export class Firestore
297297
collection(this._delegate, pathString)
298298
);
299299
} catch (e) {
300-
throw replaceFunctionName(e, 'collection()', 'Firestore.collection()');
300+
throw replaceFunctionName(
301+
e as Error,
302+
'collection()',
303+
'Firestore.collection()'
304+
);
301305
}
302306
}
303307

304308
doc(pathString: string): PublicDocumentReference {
305309
try {
306310
return new DocumentReference(this, doc(this._delegate, pathString));
307311
} catch (e) {
308-
throw replaceFunctionName(e, 'doc()', 'Firestore.doc()');
312+
throw replaceFunctionName(e as Error, 'doc()', 'Firestore.doc()');
309313
}
310314
}
311315

@@ -314,7 +318,7 @@ export class Firestore
314318
return new Query(this, collectionGroup(this._delegate, collectionId));
315319
} catch (e) {
316320
throw replaceFunctionName(
317-
e,
321+
e as Error,
318322
'collectionGroup()',
319323
'Firestore.collectionGroup()'
320324
);
@@ -687,7 +691,7 @@ export class DocumentReference<T = PublicDocumentData>
687691
);
688692
} catch (e) {
689693
throw replaceFunctionName(
690-
e,
694+
e as Error,
691695
'collection()',
692696
'DocumentReference.collection()'
693697
);
@@ -718,7 +722,11 @@ export class DocumentReference<T = PublicDocumentData>
718722
return setDoc(this._delegate, value as WithFieldValue<T>);
719723
}
720724
} catch (e) {
721-
throw replaceFunctionName(e, 'setDoc()', 'DocumentReference.set()');
725+
throw replaceFunctionName(
726+
e as Error,
727+
'setDoc()',
728+
'DocumentReference.set()'
729+
);
722730
}
723731
}
724732

@@ -745,7 +753,11 @@ export class DocumentReference<T = PublicDocumentData>
745753
);
746754
}
747755
} catch (e) {
748-
throw replaceFunctionName(e, 'updateDoc()', 'DocumentReference.update()');
756+
throw replaceFunctionName(
757+
e as Error,
758+
'updateDoc()',
759+
'DocumentReference.update()'
760+
);
749761
}
750762
}
751763

@@ -991,7 +1003,11 @@ export class Query<T = PublicDocumentData>
9911003
query(this._delegate, where(fieldPath as string, opStr, value))
9921004
);
9931005
} catch (e) {
994-
throw replaceFunctionName(e, /(orderBy|where)\(\)/, 'Query.$1()');
1006+
throw replaceFunctionName(
1007+
e as Error,
1008+
/(orderBy|where)\(\)/,
1009+
'Query.$1()'
1010+
);
9951011
}
9961012
}
9971013

@@ -1008,15 +1024,19 @@ export class Query<T = PublicDocumentData>
10081024
query(this._delegate, orderBy(fieldPath as string, directionStr))
10091025
);
10101026
} catch (e) {
1011-
throw replaceFunctionName(e, /(orderBy|where)\(\)/, 'Query.$1()');
1027+
throw replaceFunctionName(
1028+
e as Error,
1029+
/(orderBy|where)\(\)/,
1030+
'Query.$1()'
1031+
);
10121032
}
10131033
}
10141034

10151035
limit(n: number): Query<T> {
10161036
try {
10171037
return new Query<T>(this.firestore, query(this._delegate, limit(n)));
10181038
} catch (e) {
1019-
throw replaceFunctionName(e, 'limit()', 'Query.limit()');
1039+
throw replaceFunctionName(e as Error, 'limit()', 'Query.limit()');
10201040
}
10211041
}
10221042

@@ -1027,15 +1047,19 @@ export class Query<T = PublicDocumentData>
10271047
query(this._delegate, limitToLast(n))
10281048
);
10291049
} catch (e) {
1030-
throw replaceFunctionName(e, 'limitToLast()', 'Query.limitToLast()');
1050+
throw replaceFunctionName(
1051+
e as Error,
1052+
'limitToLast()',
1053+
'Query.limitToLast()'
1054+
);
10311055
}
10321056
}
10331057

10341058
startAt(...args: any[]): Query<T> {
10351059
try {
10361060
return new Query(this.firestore, query(this._delegate, startAt(...args)));
10371061
} catch (e) {
1038-
throw replaceFunctionName(e, 'startAt()', 'Query.startAt()');
1062+
throw replaceFunctionName(e as Error, 'startAt()', 'Query.startAt()');
10391063
}
10401064
}
10411065

@@ -1046,7 +1070,11 @@ export class Query<T = PublicDocumentData>
10461070
query(this._delegate, startAfter(...args))
10471071
);
10481072
} catch (e) {
1049-
throw replaceFunctionName(e, 'startAfter()', 'Query.startAfter()');
1073+
throw replaceFunctionName(
1074+
e as Error,
1075+
'startAfter()',
1076+
'Query.startAfter()'
1077+
);
10501078
}
10511079
}
10521080

@@ -1057,15 +1085,15 @@ export class Query<T = PublicDocumentData>
10571085
query(this._delegate, endBefore(...args))
10581086
);
10591087
} catch (e) {
1060-
throw replaceFunctionName(e, 'endBefore()', 'Query.endBefore()');
1088+
throw replaceFunctionName(e as Error, 'endBefore()', 'Query.endBefore()');
10611089
}
10621090
}
10631091

10641092
endAt(...args: any[]): Query<T> {
10651093
try {
10661094
return new Query(this.firestore, query(this._delegate, endAt(...args)));
10671095
} catch (e) {
1068-
throw replaceFunctionName(e, 'endAt()', 'Query.endAt()');
1096+
throw replaceFunctionName(e as Error, 'endAt()', 'Query.endAt()');
10691097
}
10701098
}
10711099

@@ -1265,7 +1293,11 @@ export class CollectionReference<T = PublicDocumentData>
12651293
);
12661294
}
12671295
} catch (e) {
1268-
throw replaceFunctionName(e, 'doc()', 'CollectionReference.doc()');
1296+
throw replaceFunctionName(
1297+
e as Error,
1298+
'doc()',
1299+
'CollectionReference.doc()'
1300+
);
12691301
}
12701302
}
12711303

packages/firestore/src/core/event_manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export async function eventManagerListen(
9797
queryInfo.viewSnap = await eventManagerImpl.onListen(query);
9898
} catch (e) {
9999
const firestoreError = wrapInUserErrorIfRecoverable(
100-
e,
100+
e as Error,
101101
`Initialization of query '${stringifyQuery(listener.query)}' failed`
102102
);
103103
listener.onError(firestoreError);

packages/messaging/src/helpers/registerDefaultSw.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export async function registerDefaultSw(
4141
});
4242
} catch (e) {
4343
throw ERROR_FACTORY.create(ErrorCode.FAILED_DEFAULT_REGISTRATION, {
44-
browserErrorMessage: e.message
44+
browserErrorMessage: (e as Error)?.message
4545
});
4646
}
4747
}

repo-scripts/api-documenter/src/plugin/PluginLoader.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ export class PluginLoader {
124124
);
125125
} catch (e) {
126126
throw new Error(
127-
`Failed to construct feature subclass:\n` + e.toString()
127+
`Failed to construct feature subclass:\n` +
128+
(e as Error)?.toString()
128129
);
129130
}
130131
if (
@@ -140,7 +141,7 @@ export class PluginLoader {
140141
} catch (e) {
141142
throw new Error(
142143
'Error occurred during the onInitialized() event: ' +
143-
e.toString()
144+
(e as Error)?.toString()
144145
);
145146
}
146147

@@ -153,7 +154,8 @@ export class PluginLoader {
153154
}
154155
} catch (e) {
155156
throw new Error(
156-
`Error loading plugin ${configPlugin.packageName}: ` + e.message
157+
`Error loading plugin ${configPlugin.packageName}: ` +
158+
(e as Error)?.message
157159
);
158160
}
159161
}

scripts/ci/check_changeset.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,11 @@ async function main() {
126126
await exec(`yarn changeset status`);
127127
console.log(`::set-output name=BLOCKING_FAILURE::false`);
128128
} catch (e) {
129-
if (e.message.match('No changesets present')) {
129+
const error = e as Error;
130+
if (error.message.match('No changesets present')) {
130131
console.log(`::set-output name=BLOCKING_FAILURE::false`);
131132
} else {
132-
const messageLines = e.message.replace(/🦋 error /g, '').split('\n');
133+
const messageLines = error.message.replace(/🦋 error /g, '').split('\n');
133134
let formattedStatusError =
134135
'- Changeset formatting error in following file:%0A';
135136
formattedStatusError += ' ```%0A';

0 commit comments

Comments
 (0)