Skip to content

Commit f9361ff

Browse files
committed
Update error handling for TS v4.4 unknown vars
1 parent 497d34c commit f9361ff

File tree

8 files changed

+27
-26
lines changed

8 files changed

+27
-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: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -297,15 +297,15 @@ export class Firestore
297297
collection(this._delegate, pathString)
298298
);
299299
} catch (e) {
300-
throw replaceFunctionName(e, 'collection()', 'Firestore.collection()');
300+
throw replaceFunctionName(e as Error, 'collection()', 'Firestore.collection()');
301301
}
302302
}
303303

304304
doc(pathString: string): PublicDocumentReference {
305305
try {
306306
return new DocumentReference(this, doc(this._delegate, pathString));
307307
} catch (e) {
308-
throw replaceFunctionName(e, 'doc()', 'Firestore.doc()');
308+
throw replaceFunctionName(e as Error, 'doc()', 'Firestore.doc()');
309309
}
310310
}
311311

@@ -314,7 +314,7 @@ export class Firestore
314314
return new Query(this, collectionGroup(this._delegate, collectionId));
315315
} catch (e) {
316316
throw replaceFunctionName(
317-
e,
317+
e as Error,
318318
'collectionGroup()',
319319
'Firestore.collectionGroup()'
320320
);
@@ -687,7 +687,7 @@ export class DocumentReference<T = PublicDocumentData>
687687
);
688688
} catch (e) {
689689
throw replaceFunctionName(
690-
e,
690+
e as Error,
691691
'collection()',
692692
'DocumentReference.collection()'
693693
);
@@ -718,7 +718,7 @@ export class DocumentReference<T = PublicDocumentData>
718718
return setDoc(this._delegate, value as WithFieldValue<T>);
719719
}
720720
} catch (e) {
721-
throw replaceFunctionName(e, 'setDoc()', 'DocumentReference.set()');
721+
throw replaceFunctionName(e as Error, 'setDoc()', 'DocumentReference.set()');
722722
}
723723
}
724724

@@ -745,7 +745,7 @@ export class DocumentReference<T = PublicDocumentData>
745745
);
746746
}
747747
} catch (e) {
748-
throw replaceFunctionName(e, 'updateDoc()', 'DocumentReference.update()');
748+
throw replaceFunctionName(e as Error, 'updateDoc()', 'DocumentReference.update()');
749749
}
750750
}
751751

@@ -991,7 +991,7 @@ export class Query<T = PublicDocumentData>
991991
query(this._delegate, where(fieldPath as string, opStr, value))
992992
);
993993
} catch (e) {
994-
throw replaceFunctionName(e, /(orderBy|where)\(\)/, 'Query.$1()');
994+
throw replaceFunctionName(e as Error, /(orderBy|where)\(\)/, 'Query.$1()');
995995
}
996996
}
997997

@@ -1008,15 +1008,15 @@ export class Query<T = PublicDocumentData>
10081008
query(this._delegate, orderBy(fieldPath as string, directionStr))
10091009
);
10101010
} catch (e) {
1011-
throw replaceFunctionName(e, /(orderBy|where)\(\)/, 'Query.$1()');
1011+
throw replaceFunctionName(e as Error, /(orderBy|where)\(\)/, 'Query.$1()');
10121012
}
10131013
}
10141014

10151015
limit(n: number): Query<T> {
10161016
try {
10171017
return new Query<T>(this.firestore, query(this._delegate, limit(n)));
10181018
} catch (e) {
1019-
throw replaceFunctionName(e, 'limit()', 'Query.limit()');
1019+
throw replaceFunctionName(e as Error, 'limit()', 'Query.limit()');
10201020
}
10211021
}
10221022

@@ -1027,15 +1027,15 @@ export class Query<T = PublicDocumentData>
10271027
query(this._delegate, limitToLast(n))
10281028
);
10291029
} catch (e) {
1030-
throw replaceFunctionName(e, 'limitToLast()', 'Query.limitToLast()');
1030+
throw replaceFunctionName(e as Error, 'limitToLast()', 'Query.limitToLast()');
10311031
}
10321032
}
10331033

10341034
startAt(...args: any[]): Query<T> {
10351035
try {
10361036
return new Query(this.firestore, query(this._delegate, startAt(...args)));
10371037
} catch (e) {
1038-
throw replaceFunctionName(e, 'startAt()', 'Query.startAt()');
1038+
throw replaceFunctionName(e as Error, 'startAt()', 'Query.startAt()');
10391039
}
10401040
}
10411041

@@ -1046,7 +1046,7 @@ export class Query<T = PublicDocumentData>
10461046
query(this._delegate, startAfter(...args))
10471047
);
10481048
} catch (e) {
1049-
throw replaceFunctionName(e, 'startAfter()', 'Query.startAfter()');
1049+
throw replaceFunctionName(e as Error, 'startAfter()', 'Query.startAfter()');
10501050
}
10511051
}
10521052

@@ -1057,15 +1057,15 @@ export class Query<T = PublicDocumentData>
10571057
query(this._delegate, endBefore(...args))
10581058
);
10591059
} catch (e) {
1060-
throw replaceFunctionName(e, 'endBefore()', 'Query.endBefore()');
1060+
throw replaceFunctionName(e as Error, 'endBefore()', 'Query.endBefore()');
10611061
}
10621062
}
10631063

10641064
endAt(...args: any[]): Query<T> {
10651065
try {
10661066
return new Query(this.firestore, query(this._delegate, endAt(...args)));
10671067
} catch (e) {
1068-
throw replaceFunctionName(e, 'endAt()', 'Query.endAt()');
1068+
throw replaceFunctionName(e as Error, 'endAt()', 'Query.endAt()');
10691069
}
10701070
}
10711071

@@ -1265,7 +1265,7 @@ export class CollectionReference<T = PublicDocumentData>
12651265
);
12661266
}
12671267
} catch (e) {
1268-
throw replaceFunctionName(e, 'doc()', 'CollectionReference.doc()');
1268+
throw replaceFunctionName(e as Error, 'doc()', 'CollectionReference.doc()');
12691269
}
12701270
}
12711271

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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ 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` + (e as Error)?.toString()
128128
);
129129
}
130130
if (
@@ -140,7 +140,7 @@ export class PluginLoader {
140140
} catch (e) {
141141
throw new Error(
142142
'Error occurred during the onInitialized() event: ' +
143-
e.toString()
143+
(e as Error)?.toString()
144144
);
145145
}
146146

@@ -153,7 +153,7 @@ export class PluginLoader {
153153
}
154154
} catch (e) {
155155
throw new Error(
156-
`Error loading plugin ${configPlugin.packageName}: ` + e.message
156+
`Error loading plugin ${configPlugin.packageName}: ` + (e as Error)?.message
157157
);
158158
}
159159
}

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)