thread-stream
thread-stream copied to clipboard
Custom error objects aren't cloneable
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.