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

lib: remove NodeError from the prototype of errors with code #33857

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 28 additions & 24 deletions lib/internal/errors.js
Expand Up @@ -248,31 +248,35 @@ function makeSystemErrorWithCode(key) {
}

function makeNodeErrorWithCode(Base, key) {
return class NodeError extends Base {
constructor(...args) {
if (excludedStackFn === undefined) {
super();
} else {
const limit = Error.stackTraceLimit;
Error.stackTraceLimit = 0;
super();
// Reset the limit and setting the name property.
Error.stackTraceLimit = limit;
}
const message = getMessage(key, args, this);
ObjectDefineProperty(this, 'message', {
value: message,
enumerable: false,
writable: true,
configurable: true
});
addCodeToName(this, super.name, key);
this.code = key;
}

toString() {
return `${this.name} [${key}]: ${this.message}`;
return function NodeError(...args) {
let error;
if (excludedStackFn === undefined) {
error = new Base();
} else {
const limit = Error.stackTraceLimit;
Error.stackTraceLimit = 0;
error = new Base();
// Reset the limit and setting the name property.
Error.stackTraceLimit = limit;
}
const message = getMessage(key, args, error);
ObjectDefineProperty(error, 'message', {
value: message,
enumerable: false,
writable: true,
configurable: true,
});
ObjectDefineProperty(error, 'toString', {
value() {
return `${this.name} [${key}]: ${this.message}`;
},
enumerable: false,
writable: true,
configurable: true,
});
addCodeToName(error, Base.name, key);
error.code = key;
return error;
};
}

Expand Down
4 changes: 2 additions & 2 deletions test/message/esm_loader_not_found.out
Expand Up @@ -4,6 +4,7 @@ internal/modules/run_main.js:*
internalBinding('errors').triggerUncaughtException(
^
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'i-dont-exist' imported from *
at new NodeError (internal/errors.js:*:*)
at packageResolve (internal/modules/esm/resolve.js:*:*)
at moduleResolve (internal/modules/esm/resolve.js:*:*)
at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:*:*)
Expand All @@ -12,7 +13,6 @@ Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'i-dont-exist' imported from *
at Loader.import (internal/modules/esm/loader.js:*:*)
at internal/process/esm_loader.js:*:*
at Object.initializeLoader (internal/process/esm_loader.js:*:*)
at runMainESM (internal/modules/run_main.js:*:*)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:*:*) {
at runMainESM (internal/modules/run_main.js:*:*) {
code: 'ERR_MODULE_NOT_FOUND'
}
1 change: 1 addition & 0 deletions test/message/esm_loader_not_found_cjs_hint_bare.out
Expand Up @@ -4,6 +4,7 @@ internal/modules/run_main.js:*

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '*test*fixtures*node_modules*some_module*obj' imported from *test*fixtures*esm_loader_not_found_cjs_hint_bare.mjs
Did you mean to import some_module/obj.js?
at new NodeError (internal/errors.js:*:*)
at finalizeResolution (internal/modules/esm/resolve.js:*:*)
at packageResolve (internal/modules/esm/resolve.js:*:*)
at moduleResolve (internal/modules/esm/resolve.js:*:*)
Expand Down
4 changes: 2 additions & 2 deletions test/message/esm_loader_not_found_cjs_hint_relative.out
Expand Up @@ -6,6 +6,7 @@ internal/modules/run_main.js:*

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '*test*common*fixtures' imported from *
Did you mean to import ./test/common/fixtures.js?
at new NodeError (internal/errors.js:*:*)
at finalizeResolution (internal/modules/esm/resolve.js:*:*)
at moduleResolve (internal/modules/esm/resolve.js:*:*)
at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:*:*)
Expand All @@ -14,7 +15,6 @@ Did you mean to import ./test/common/fixtures.js?
at Loader.import (internal/modules/esm/loader.js:*:*)
at internal/process/esm_loader.js:*:*
at Object.initializeLoader (internal/process/esm_loader.js:*:*)
at runMainESM (internal/modules/run_main.js:*:*)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:*:*) {
at runMainESM (internal/modules/run_main.js:*:*) {
code: 'ERR_MODULE_NOT_FOUND'
}
1 change: 1 addition & 0 deletions test/message/internal_assert.out
Expand Up @@ -5,6 +5,7 @@ internal/assert.js:*
Error [ERR_INTERNAL_ASSERTION]: This is caused by either a bug in Node.js or incorrect usage of Node.js internals.
Please open an issue with this stack trace at https://github.com/nodejs/node/issues

at new NodeError (internal/errors.js:*:*)
at assert (internal/assert.js:*:*)
at * (*test*message*internal_assert.js:7:1)
at *
Expand Down
1 change: 1 addition & 0 deletions test/message/internal_assert_fail.out
Expand Up @@ -6,6 +6,7 @@ Error [ERR_INTERNAL_ASSERTION]: Unreachable!
This is caused by either a bug in Node.js or incorrect usage of Node.js internals.
Please open an issue with this stack trace at https://github.com/nodejs/node/issues

at new NodeError (internal/errors.js:*:*)
at Function.fail (internal/assert.js:*:*)
at * (*test*message*internal_assert_fail.js:7:8)
at *
Expand Down