-
-
Notifications
You must be signed in to change notification settings - Fork 34.7k
lib: deserialize to native errors in error_serdes #58605
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,34 @@ | ||||||||
| 'use strict'; | ||||||||
| const common = require('../common'); | ||||||||
| const assert = require('assert'); | ||||||||
| const { isNativeError } = require('util/types'); | ||||||||
| const { Worker } = require('worker_threads'); | ||||||||
|
|
||||||||
| const validateError = (error, ctor) => { | ||||||||
| assert.strictEqual(error.constructor, ctor); | ||||||||
| assert.strictEqual(Object.getPrototypeOf(error), ctor.prototype); | ||||||||
| assert(isNativeError(error)); | ||||||||
| }; | ||||||||
|
|
||||||||
| { | ||||||||
| const w = new Worker('throw new Error()', { eval: true }); | ||||||||
| w.on('error', common.mustCall((error) => { | ||||||||
| validateError(error, Error); | ||||||||
| })); | ||||||||
| } | ||||||||
|
|
||||||||
| { | ||||||||
| const w = new Worker('throw new RangeError()', { eval: true }); | ||||||||
| w.on('error', common.mustCall((error) => { | ||||||||
| validateError(error, RangeError); | ||||||||
| })); | ||||||||
| } | ||||||||
|
|
||||||||
| { | ||||||||
| const w = new Worker('throw new Error(undefined, { cause: new TypeError() })', { eval: true }); | ||||||||
| w.on('error', common.mustCall((error) => { | ||||||||
| validateError(error, Error); | ||||||||
| assert.notStrictEqual(error.cause, undefined); | ||||||||
| validateError(error.cause, TypeError); | ||||||||
| })); | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be worth expanding this test to see if it works with the new
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did consider AggregateError, although neither of these are explicitly handled currently. node/lib/internal/error_serdes.js Lines 46 to 48 in b353e31
At the moment, the logic traverses the prototype chain and ends up serialising these as Errors, so they end up with a prototype of
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added a TODO to error_serdes for the uncovered constructors. |
||||||||
| } | ||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this previous behaviour was a result of always assigning
[Symbol.toStringTag]: 'Error'on the deserialised error.