thread-stream icon indicating copy to clipboard operation
thread-stream copied to clipboard

Custom error objects aren't cloneable

Open jasnell opened this issue 2 years ago • 4 comments

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.

jasnell avatar Jul 21 '21 14:07 jasnell