Skip to content

Commit 3b481f5

Browse files
Change FirestoreError to extend FirebaseError (#5831)
1 parent 3d8109c commit 3b481f5

File tree

11 files changed

+93
-15
lines changed

11 files changed

+93
-15
lines changed

.changeset/big-otters-reply.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@firebase/firestore": patch
3+
"@firebase/storage": patch
4+
"@firebase/util": patch
5+
---
6+
7+
FirestoreError and StorageError now extend FirebaseError

common/api-review/firestore-lite.api.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import { EmulatorMockTokenOptions } from '@firebase/util';
88
import { FirebaseApp } from '@firebase/app';
9+
import { FirebaseError } from '@firebase/util';
910
import { LogLevelString as LogLevel } from '@firebase/logger';
1011

1112
// @public
@@ -147,10 +148,9 @@ export interface FirestoreDataConverter<T> {
147148
}
148149

149150
// @public
150-
export class FirestoreError extends Error {
151+
export class FirestoreError extends FirebaseError {
151152
readonly code: FirestoreErrorCode;
152153
readonly message: string;
153-
readonly name: string;
154154
readonly stack?: string;
155155
}
156156

common/api-review/firestore.api.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import { EmulatorMockTokenOptions } from '@firebase/util';
88
import { FirebaseApp } from '@firebase/app';
9+
import { FirebaseError } from '@firebase/util';
910
import { LogLevelString as LogLevel } from '@firebase/logger';
1011

1112
// @public
@@ -177,10 +178,9 @@ export interface FirestoreDataConverter<T> {
177178
}
178179

179180
// @public
180-
export class FirestoreError extends Error {
181+
export class FirestoreError extends FirebaseError {
181182
readonly code: FirestoreErrorCode;
182183
readonly message: string;
183-
readonly name: string;
184184
readonly stack?: string;
185185
}
186186

packages/firestore/src/util/error.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* limitations under the License.
1616
*/
1717

18+
import { FirebaseError } from '@firebase/util';
19+
1820
/**
1921
* The set of Firestore status codes. The codes are the same at the ones
2022
* exposed by gRPC here:
@@ -208,10 +210,7 @@ export const Code = {
208210
};
209211

210212
/** An error returned by a Firestore operation. */
211-
export class FirestoreError extends Error {
212-
/** The custom name for all FirestoreErrors. */
213-
readonly name: string = 'FirebaseError';
214-
213+
export class FirestoreError extends FirebaseError {
215214
/** The stack of the error. */
216215
readonly stack?: string;
217216

@@ -226,7 +225,7 @@ export class FirestoreError extends Error {
226225
*/
227226
readonly message: string
228227
) {
229-
super(message);
228+
super(code, message);
230229

231230
// HACK: We write a toString property directly because Error is not a real
232231
// class and so inheritance does not work correctly. We could alternatively

packages/storage/src/implementation/error.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { FirebaseError } from '@firebase/util';
21
/**
32
* @license
43
* Copyright 2017 Google LLC
@@ -15,6 +14,9 @@ import { FirebaseError } from '@firebase/util';
1514
* See the License for the specific language governing permissions and
1615
* limitations under the License.
1716
*/
17+
18+
import { FirebaseError } from '@firebase/util';
19+
1820
import { CONFIG_STORAGE_BUCKET_KEY } from './constants';
1921

2022
/**

packages/util/src/errors.ts

+3
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,14 @@ export interface ErrorData {
7272
// Based on code from:
7373
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#Custom_Error_Types
7474
export class FirebaseError extends Error {
75+
/** The custom name for all FirebaseErrors. */
7576
readonly name = ERROR_NAME;
7677

7778
constructor(
79+
/** The error code for this error. */
7880
readonly code: string,
7981
message: string,
82+
/** Custom data for this error. */
8083
public customData?: Record<string, unknown>
8184
) {
8285
super(message);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="All Tests" type="mocha-javascript-test-runner">
3+
<node-interpreter>project</node-interpreter>
4+
<node-options />
5+
<mocha-package>$PROJECT_DIR$/../../node_modules/mocha</mocha-package>
6+
<working-directory>$PROJECT_DIR$</working-directory>
7+
<pass-parent-env>true</pass-parent-env>
8+
<envs>
9+
<env name="TS_NODE_COMPILER_OPTIONS" value="{&quot;module&quot;:&quot;commonjs&quot;}" />
10+
<env name="TS_NODE_FILES" value="true" />
11+
<env name="TS_NODE_CACHE" value="NO" />
12+
</envs>
13+
<ui>bdd</ui>
14+
<extra-mocha-options>--require ts-node/register/type-check</extra-mocha-options>
15+
<test-kind>PATTERN</test-kind>
16+
<test-pattern>*.test.ts</test-pattern>
17+
<method v="2" />
18+
</configuration>
19+
</component>

repo-scripts/prune-dts/extract-public-api.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export async function generateApi(
138138
untrimmedRollupDtsPath: string,
139139
publicDtsPath: string
140140
): Promise<void> {
141-
console.log(`Configuring API Extractor for #{packageName}`);
141+
console.log(`Configuring API Extractor for ${packageName}`);
142142
writeTypescriptConfig(packageRoot);
143143
writePackageJson(packageName);
144144

repo-scripts/prune-dts/prune-dts.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,15 @@ function isExported(
119119
sourceFile: ts.SourceFile,
120120
name: ts.Identifier
121121
): boolean {
122+
const declarations =
123+
typeChecker.getSymbolAtLocation(name)?.declarations ?? [];
124+
122125
// Check is this is a public symbol (e.g. part of the DOM library)
123-
const sourceFileNames = typeChecker
124-
.getSymbolAtLocation(name)
125-
?.declarations?.map(d => d.getSourceFile().fileName);
126-
if (sourceFileNames?.find(s => s.indexOf('typescript/lib') != -1)) {
126+
const isTypescriptType = declarations.find(
127+
d => d.getSourceFile().fileName.indexOf('typescript/lib') != -1
128+
);
129+
const isImported = declarations.find(d => ts.isImportSpecifier(d));
130+
if (isTypescriptType || isImported) {
127131
return true;
128132
}
129133

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @license
3+
* Copyright 2021 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
import { FirebaseError } from '@firebase/util';
18+
19+
export declare interface StorageError extends FirebaseError {
20+
serverResponse: string | null;
21+
}
22+
23+
export {};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @license
3+
* Copyright 2021 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
import { FirebaseError } from '@firebase/util';
18+
export declare interface StorageError extends FirebaseError {
19+
serverResponse: string | null;
20+
}
21+
export {};

0 commit comments

Comments
 (0)