Skip to content

Commit 0197076

Browse files
authored
Update error handling for TS v4.4 unknown variables (#6326)
* Update error handling for TS v4.4 unknown vars * Update formating for import
1 parent f84cacd commit 0197076

File tree

8 files changed

+14
-12
lines changed

8 files changed

+14
-12
lines changed

packages/functions/src/callable.test.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
import { makeFakeApp, createTestService } from '../test/utils';
3636
import { httpsCallable } from './service';
3737
import { FUNCTIONS_TYPE } from './constants';
38+
import { FunctionsError } from './error';
3839

3940
// eslint-disable-next-line @typescript-eslint/no-require-imports
4041
export const TEST_PROJECT = require('../../../config/project.json');
@@ -52,9 +53,10 @@ async function expectError(
5253
await promise;
5354
} catch (e) {
5455
failed = true;
55-
expect(e.code).to.equal(`${FUNCTIONS_TYPE}/${code}`);
56-
expect(e.message).to.equal(message);
57-
expect(e.details).to.deep.equal(details);
56+
const error = e as FunctionsError;
57+
expect(error.code).to.equal(`${FUNCTIONS_TYPE}/${code}`);
58+
expect(error.message).to.equal(message);
59+
expect(error.details).to.deep.equal(details);
5860
}
5961
if (!failed) {
6062
expect(false, 'Promise should have failed.').to.be.true;

packages/remote-config/src/api.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export async function fetchConfig(remoteConfig: RemoteConfig): Promise<void> {
123123

124124
await rc._storageCache.setLastFetchStatus('success');
125125
} catch (e) {
126-
const lastFetchStatus = hasErrorCode(e, ErrorCode.FETCH_THROTTLE)
126+
const lastFetchStatus = hasErrorCode(e as Error, ErrorCode.FETCH_THROTTLE)
127127
? 'throttle'
128128
: 'failure';
129129
await rc._storageCache.setLastFetchStatus(lastFetchStatus);

packages/storage/src/platform/node/connection.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ abstract class FetchConnection<T extends ConnectionType>
6969
this.errorCode_ = ErrorCode.NO_ERROR;
7070
this.body_ = await response.arrayBuffer();
7171
} catch (e) {
72-
this.errorText_ = e.message;
72+
this.errorText_ = (e as Error)?.message;
7373
// emulate XHR which sets status to 0 when encountering a network error
7474
this.statusCode_ = 0;
7575
this.errorCode_ = ErrorCode.NETWORK_ERROR;
@@ -171,7 +171,7 @@ export class FetchStreamConnection extends FetchConnection<NodeJS.ReadableStream
171171
this.errorCode_ = ErrorCode.NO_ERROR;
172172
this.stream_ = response.body;
173173
} catch (e) {
174-
this.errorText_ = e.message;
174+
this.errorText_ = (e as Error)?.message;
175175
// emulate XHR which sets status to 0 when encountering a network error
176176
this.statusCode_ = 0;
177177
this.errorCode_ = ErrorCode.NETWORK_ERROR;

packages/storage/src/task.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ export class UploadTask {
275275
this._makeProgressCallback()
276276
);
277277
} catch (e) {
278-
this._error = e;
278+
this._error = e as StorageError;
279279
this._transition(InternalTaskState.ERROR);
280280
return;
281281
}

packages/storage/test/browser/blob.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ describe('Firebase Storage > Blob', () => {
114114
await getBlob(reference);
115115
expect.fail();
116116
} catch (e) {
117-
expect(e.message).to.satisfy((v: string) =>
117+
expect((e as Error)?.message).to.satisfy((v: string) =>
118118
v.match(/Object 'public\/exp-bytes-missing' does not exist/)
119119
);
120120
}

packages/storage/test/integration/integration.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ describe('FirebaseStorage Exp', () => {
103103
await getBytes(reference);
104104
expect.fail();
105105
} catch (e) {
106-
expect(e.message).to.satisfy((v: string) =>
106+
expect((e as Error)?.message).to.satisfy((v: string) =>
107107
v.match(/Object 'public\/exp-bytes-missing' does not exist/)
108108
);
109109
}
@@ -130,7 +130,7 @@ describe('FirebaseStorage Exp', () => {
130130
await uploadString(reference, 'foo');
131131
expect.fail();
132132
} catch (e) {
133-
expect(e.message).to.satisfy((v: string) =>
133+
expect((e as Error)?.message).to.satisfy((v: string) =>
134134
v.match(
135135
/The operation 'uploadString' cannot be performed on a root reference/
136136
)

packages/storage/test/node/stream.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ describe('Firebase Storage > getStream', () => {
6868
await readData(stream);
6969
expect.fail();
7070
} catch (e) {
71-
expect(e.message).to.satisfy((v: string) =>
71+
expect((e as Error)?.message).to.satisfy((v: string) =>
7272
v.match(/Object 'public\/exp-bytes-missing' does not exist/)
7373
);
7474
}

packages/storage/test/unit/testshared.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export function assertThrows(f: () => void, code: string): StorageError {
156156
try {
157157
f();
158158
} catch (e) {
159-
captured = e;
159+
captured = e as StorageError;
160160
throw e;
161161
}
162162
}).to.throw();

0 commit comments

Comments
 (0)