Skip to content

Node 20: errors with util.inspect.custom raised in loader thread not serialized/deserialized correctly #48207

Closed
@danrr

Description

@danrr

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.

  1. 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)
  2. 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]]
}
  1. 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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions