Skip to content

Custom error objects aren't cloneable #29

Open
@jasnell

Description

@jasnell

Just something to remember... in https://github.com/pinojs/thread-stream/blob/main/lib/worker.js, when the destination error event is emitted, an 'ERROR' message is posted back to the origin thread...

https://github.com/pinojs/thread-stream/blob/main/lib/worker.js#L21-L26:

  destination.on('error', function (err) {
    parentPort.postMessage({
      code: 'ERROR',
      err
    })
  })

Error objects can be a bit odd in the structured clone algorithm. If err is a custom error object (e.g. something like Node.js DOMException or something like class MyError extends Error, what comes out on the other side will not match exactly. It will certainly clone as an Error, but you'll lose the custom extension on it.

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