Skip to content

Display a helpful error instead of Unexpected Error for key validation#10789

Open
Berlioz wants to merge 1 commit into
mainfrom
vsfan_key_errors
Open

Display a helpful error instead of Unexpected Error for key validation#10789
Berlioz wants to merge 1 commit into
mainfrom
vsfan_key_errors

Conversation

@Berlioz

@Berlioz Berlioz commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Because KeyValidationError wasn't instanceof FirebaseError, the catchall error handler in errorOut.ts was just printing "Error: An unexpected error has occurred"

…n failures while loading or writing to .envs

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/functions/env.ts
}

export class KeyValidationError extends Error {
export class KeyValidationError extends FirebaseError {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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 shettyvarun268 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might need to take off public from the constructor as per what gemini says. But overall, LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants