Display a helpful error instead of Unexpected Error for key validation#10789
Display a helpful error instead of Unexpected Error for key validation#10789Berlioz wants to merge 1 commit into
Conversation
…n failures while loading or writing to .envs
There was a problem hiding this comment.
Code Review
This pull request updates the KeyValidationError class to extend FirebaseError instead of the standard Error class. The review feedback correctly identifies a critical issue where the TypeScript constructor parameter property public message: string will overwrite the error message initialized by super(), causing the error prefix to be lost. It is recommended to remove the public keyword from the message parameter to prevent this behavior.
| } | ||
|
|
||
| export class KeyValidationError extends Error { | ||
| export class KeyValidationError extends FirebaseError { |
There was a problem hiding this comment.
In TypeScript, constructor parameter properties (like public message: string) are initialized after the super() call runs.
Because KeyValidationError now extends FirebaseError (which inherits Error.prototype.message), calling super(...) sets the error message, but it is immediately overwritten by this.message = message once super() returns. This causes the "Failed to validate key ..." prefix to be completely lost.
To fix this, remove the public keyword from the message parameter so it is not treated as a parameter property:
export class KeyValidationError extends FirebaseError {
constructor(
public key: string,
message: string,
) {
super(`Failed to validate key ${key}: ${message}`);
}
}
shettyvarun268
left a comment
There was a problem hiding this comment.
We might need to take off public from the constructor as per what gemini says. But overall, LGTM
Because KeyValidationError wasn't instanceof FirebaseError, the catchall error handler in errorOut.ts was just printing "Error: An unexpected error has occurred"