Closed
Description
Version
v20.2.0
Platform
No response
Subsystem
No response
What steps will reproduce the bug?
Throw an error with a custom inspect symbol in worker thread, which is then serialised and deserialised to be displayed by main thread.
Investigating a bug in ts-node
(TypeStrong/ts-node#2026) I ran into some issues with how errors in (loader) worker threads are handled.
util.inspect.custom
is only checked in own properties (https://github.com/nodejs/node/blob/main/lib/internal/error_serdes.js#L137), ignoring it if the error was created using a class constructor (see https://github.com/TypeStrong/ts-node/blob/7af5c48864b60576e471da03c064f325ce37d850/src/index.ts#L432-L464)- Errors with custom inspect methods are not displayed correctly by call to
internalBinding('errors').triggerUncaughtException
node:internal/process/esm_loader:42
internalBinding('errors').triggerUncaughtException(
^
[Object: null prototype] {
[Symbol(nodejs.util.inspect.custom)]: [Function: [nodejs.util.inspect.custom]]
}
- Errors defined by classes inheriting from Error don't appear to trigger the check here: https://github.com/nodejs/node/blob/main/lib/internal/error_serdes.js#L120
let a = new Error("hmm?")
Object.prototype.toString(a)
> "[object Object]"
How often does it reproduce? Is there a required condition?
Every time an error is raised in loader worker thread.
What is the expected behavior? Why is that the expected behavior?
Errors using custom inspect symbol raised in threads should serialise correctly
What do you see instead?
[Symbol(nodejs.util.inspect.custom)]: [Function: [nodejs.util.inspect.custom]]
Additional information
No response
Metadata
Metadata
Assignees
Labels
No labels