-
-
Notifications
You must be signed in to change notification settings - Fork 32k
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?
lib: deserialize to native errors in error_serdes #58605
Conversation
match(stderr, /SyntaxError \[Error\]:/); | ||
match(stderr, /SyntaxError:/); |
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.
e919a34
to
b353e31
Compare
validateError(error, Error); | ||
assert.notStrictEqual(error.cause, undefined); | ||
validateError(error.cause, TypeError); | ||
})); |
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.
Would be worth expanding this test to see if it works with the new SuppressedError
and AggregateError
types.
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.
I did consider AggregateError, although neither of these are explicitly handled currently.
node/lib/internal/error_serdes.js
Lines 46 to 48 in b353e31
const errors = { | |
Error, TypeError, RangeError, URIError, SyntaxError, ReferenceError, EvalError, | |
}; |
At the moment, the logic traverses the prototype chain and ends up serialising these as Errors, so they end up with a prototype of Error.prototype
. It doesn't really fall within the scope of this PR, but I can add a todo if desired?
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #58605 +/- ##
=======================================
Coverage 90.11% 90.12%
=======================================
Files 640 640
Lines 188427 188432 +5
Branches 36965 36961 -4
=======================================
+ Hits 169804 169816 +12
+ Misses 11347 11337 -10
- Partials 7276 7279 +3
🚀 New features to boost your workflow:
|
b353e31
to
71f1340
Compare
Currently, errors deserialised by error_serdes are recreated using
Object.create()
with the source error's prototype. The objects created using this technique are not considered native errors.This was always observable using
util.types.isNativeError()
, but withError.isError()
now being exposed, this becomes more readily apparent.Closes #48716.