Skip to content

Commit

Permalink
Change FirestoreError to extend FirebaseError (#5831)
Browse files Browse the repository at this point in the history
  • Loading branch information
schmidt-sebastian authored Jan 4, 2022
1 parent 3d8109c commit 3b481f5
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 15 deletions.
7 changes: 7 additions & 0 deletions .changeset/big-otters-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@firebase/firestore": patch
"@firebase/storage": patch
"@firebase/util": patch
---

FirestoreError and StorageError now extend FirebaseError
4 changes: 2 additions & 2 deletions common/api-review/firestore-lite.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import { EmulatorMockTokenOptions } from '@firebase/util';
import { FirebaseApp } from '@firebase/app';
import { FirebaseError } from '@firebase/util';
import { LogLevelString as LogLevel } from '@firebase/logger';

// @public
Expand Down Expand Up @@ -147,10 +148,9 @@ export interface FirestoreDataConverter<T> {
}

// @public
export class FirestoreError extends Error {
export class FirestoreError extends FirebaseError {
readonly code: FirestoreErrorCode;
readonly message: string;
readonly name: string;
readonly stack?: string;
}

Expand Down
4 changes: 2 additions & 2 deletions common/api-review/firestore.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import { EmulatorMockTokenOptions } from '@firebase/util';
import { FirebaseApp } from '@firebase/app';
import { FirebaseError } from '@firebase/util';
import { LogLevelString as LogLevel } from '@firebase/logger';

// @public
Expand Down Expand Up @@ -177,10 +178,9 @@ export interface FirestoreDataConverter<T> {
}

// @public
export class FirestoreError extends Error {
export class FirestoreError extends FirebaseError {
readonly code: FirestoreErrorCode;
readonly message: string;
readonly name: string;
readonly stack?: string;
}

Expand Down
9 changes: 4 additions & 5 deletions packages/firestore/src/util/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* limitations under the License.
*/

import { FirebaseError } from '@firebase/util';

/**
* The set of Firestore status codes. The codes are the same at the ones
* exposed by gRPC here:
Expand Down Expand Up @@ -208,10 +210,7 @@ export const Code = {
};

/** An error returned by a Firestore operation. */
export class FirestoreError extends Error {
/** The custom name for all FirestoreErrors. */
readonly name: string = 'FirebaseError';

export class FirestoreError extends FirebaseError {
/** The stack of the error. */
readonly stack?: string;

Expand All @@ -226,7 +225,7 @@ export class FirestoreError extends Error {
*/
readonly message: string
) {
super(message);
super(code, message);

// HACK: We write a toString property directly because Error is not a real
// class and so inheritance does not work correctly. We could alternatively
Expand Down
4 changes: 3 additions & 1 deletion packages/storage/src/implementation/error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { FirebaseError } from '@firebase/util';
/**
* @license
* Copyright 2017 Google LLC
Expand All @@ -15,6 +14,9 @@ import { FirebaseError } from '@firebase/util';
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { FirebaseError } from '@firebase/util';

import { CONFIG_STORAGE_BUCKET_KEY } from './constants';

/**
Expand Down
3 changes: 3 additions & 0 deletions packages/util/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,14 @@ export interface ErrorData {
// Based on code from:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#Custom_Error_Types
export class FirebaseError extends Error {
/** The custom name for all FirebaseErrors. */
readonly name = ERROR_NAME;

constructor(
/** The error code for this error. */
readonly code: string,
message: string,
/** Custom data for this error. */
public customData?: Record<string, unknown>
) {
super(message);
Expand Down
19 changes: 19 additions & 0 deletions repo-scripts/prune-dts/.run/AllTests.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="All Tests" type="mocha-javascript-test-runner">
<node-interpreter>project</node-interpreter>
<node-options />
<mocha-package>$PROJECT_DIR$/../../node_modules/mocha</mocha-package>
<working-directory>$PROJECT_DIR$</working-directory>
<pass-parent-env>true</pass-parent-env>
<envs>
<env name="TS_NODE_COMPILER_OPTIONS" value="{&quot;module&quot;:&quot;commonjs&quot;}" />
<env name="TS_NODE_FILES" value="true" />
<env name="TS_NODE_CACHE" value="NO" />
</envs>
<ui>bdd</ui>
<extra-mocha-options>--require ts-node/register/type-check</extra-mocha-options>
<test-kind>PATTERN</test-kind>
<test-pattern>*.test.ts</test-pattern>
<method v="2" />
</configuration>
</component>
2 changes: 1 addition & 1 deletion repo-scripts/prune-dts/extract-public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export async function generateApi(
untrimmedRollupDtsPath: string,
publicDtsPath: string
): Promise<void> {
console.log(`Configuring API Extractor for #{packageName}`);
console.log(`Configuring API Extractor for ${packageName}`);
writeTypescriptConfig(packageRoot);
writePackageJson(packageName);

Expand Down
12 changes: 8 additions & 4 deletions repo-scripts/prune-dts/prune-dts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,15 @@ function isExported(
sourceFile: ts.SourceFile,
name: ts.Identifier
): boolean {
const declarations =
typeChecker.getSymbolAtLocation(name)?.declarations ?? [];

// Check is this is a public symbol (e.g. part of the DOM library)
const sourceFileNames = typeChecker
.getSymbolAtLocation(name)
?.declarations?.map(d => d.getSourceFile().fileName);
if (sourceFileNames?.find(s => s.indexOf('typescript/lib') != -1)) {
const isTypescriptType = declarations.find(
d => d.getSourceFile().fileName.indexOf('typescript/lib') != -1
);
const isImported = declarations.find(d => ts.isImportSpecifier(d));
if (isTypescriptType || isImported) {
return true;
}

Expand Down
23 changes: 23 additions & 0 deletions repo-scripts/prune-dts/tests/error.input.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* @license
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { FirebaseError } from '@firebase/util';

export declare interface StorageError extends FirebaseError {
serverResponse: string | null;
}

export {};
21 changes: 21 additions & 0 deletions repo-scripts/prune-dts/tests/error.output.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @license
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { FirebaseError } from '@firebase/util';
export declare interface StorageError extends FirebaseError {
serverResponse: string | null;
}
export {};

0 comments on commit 3b481f5

Please sign in to comment.