mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
worker: use correct ctor for error serialization
When serializing errors, use the error constructor that is closest to the object itself in the prototype chain. The previous practice of walking downwards meant that `Error` would usually be the first constructor that is used, even when a more specific one would be available/appropriate, because it is the base class of the other common error types. PR-URL: https://github.com/nodejs/node/pull/25951 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
8b79c15b6f
commit
de9d5ff287
@ -86,7 +86,7 @@ function serializeError(error) {
|
||||
if (typeof error === 'object' &&
|
||||
ObjectPrototypeToString(error) === '[object Error]') {
|
||||
const constructors = GetConstructors(error);
|
||||
for (var i = constructors.length - 1; i >= 0; i--) {
|
||||
for (var i = 0; i < constructors.length; i++) {
|
||||
const name = GetName(constructors[i]);
|
||||
if (errorConstructorNames.has(name)) {
|
||||
try { error.stack; } catch {}
|
||||
|
@ -10,6 +10,7 @@ if (!process.env.HAS_STARTED_WORKER) {
|
||||
const w = new Worker(fixtures.path('syntax', 'bad_syntax.js'));
|
||||
w.on('message', common.mustNotCall());
|
||||
w.on('error', common.mustCall((err) => {
|
||||
assert.strictEqual(err.constructor, SyntaxError);
|
||||
assert(/SyntaxError/.test(err));
|
||||
}));
|
||||
} else {
|
||||
|
@ -9,6 +9,7 @@ if (!process.env.HAS_STARTED_WORKER) {
|
||||
const w = new Worker('abc)', { eval: true });
|
||||
w.on('message', common.mustNotCall());
|
||||
w.on('error', common.mustCall((err) => {
|
||||
assert.strictEqual(err.constructor, SyntaxError);
|
||||
assert(/SyntaxError/.test(err));
|
||||
}));
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user