Skip to content
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

CustomError implementation triggers the override mistake #231

Closed
mhofman opened this issue Sep 24, 2023 · 2 comments · Fixed by #232
Closed

CustomError implementation triggers the override mistake #231

mhofman opened this issue Sep 24, 2023 · 2 comments · Fixed by #232

Comments

@mhofman
Copy link

mhofman commented Sep 24, 2023

The implementation of CustomError uses an assignment to set the constructor and name properties, which would trigger what is commonly known as the override mistake in an environment with frozen intrinsics (like Node.js with --frozen-intrinsics or Hardened JavaScript).

In this case, both constructor and name are properties of Error.prototype which would be frozen and thus non-writable in those environments.

The solution is to explicitly define the properties instead of using an assignment, for example:

  Object.defineProperties(CustomError.prototype, {
    constructor: {
      value: CustomError,
      enumerable: false,
      writable: true,
      configurable: true,
    },
    name: {
      value: "Error [" + code + "]",
      enumerable: false,
      writable: true,
      configurable: true,
    },
  });
@RubenVerborgh
Copy link
Collaborator

Interesting, thanks. Solved this in #232!

@mhofman
Copy link
Author

mhofman commented Sep 25, 2023

Fantastic! Thanks for the quick turnaround

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 a pull request may close this issue.

2 participants