Skip to content

Fix FirebaseStorageError message recursion bug #4807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/friendly-cooks-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@firebase/storage': patch
---

Fix infinite recursion caused by `FirebaseStorageError` message getter.
18 changes: 7 additions & 11 deletions packages/storage/src/implementation/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { CONFIG_STORAGE_BUCKET_KEY } from './constants';
* @public
*/
export class FirebaseStorageError extends FirebaseError {
private readonly _baseMessage: string;
/**
* Stores custom error data unque to FirebaseStorageError.
*/
Expand All @@ -37,6 +38,7 @@ export class FirebaseStorageError extends FirebaseError {
prependCode(code),
`Firebase Storage: ${message} (${prependCode(code)})`
);
this._baseMessage = this.message;
// Without this, `instanceof FirebaseStorageError`, in tests for example,
// returns false.
Object.setPrototypeOf(this, FirebaseStorageError.prototype);
Expand All @@ -49,17 +51,6 @@ export class FirebaseStorageError extends FirebaseError {
return prependCode(code) === this.code;
}

/**
* Error message including serverResponse if available.
*/
get message(): string {
if (this.customData.serverResponse) {
return `${this.message}\n${this.customData.serverResponse}`;
} else {
return this.message;
}
}

/**
* Optional response message that was added by the server.
*/
Expand All @@ -69,6 +60,11 @@ export class FirebaseStorageError extends FirebaseError {

set serverResponse(serverResponse: string | null) {
this.customData.serverResponse = serverResponse;
if (this.customData.serverResponse) {
this.message = `${this._baseMessage}\n${this.customData.serverResponse}`;
} else {
this.message = this._baseMessage;
}
}
}

Expand Down