mirror of https://github.com/nodejs/node.git
lib: remove NodeError from the prototype of errors with code
Signed-off-by: Michaël Zasso <targos@protonmail.com> PR-URL: https://github.com/nodejs/node/pull/33857 Refs: https://github.com/nodejs/node/pull/33770 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Zeyu Yang <himself65@outlook.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>pull/33974/head
parent
646e5a4717
commit
a86a295fd7
|
@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -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:*:*)
|
||||
|
@ -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'
|
||||
}
|
||||
|
|
|
@ -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:*:*)
|
||||
|
|
|
@ -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:*:*)
|
||||
|
@ -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'
|
||||
}
|
||||
|
|
|
@ -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 *
|
||||
|
|
|
@ -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 *
|
||||
|
|
Loading…
Reference in New Issue