Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom error objects aren't cloneable #29

Open
jasnell opened this issue Jul 21, 2021 · 4 comments
Open

Custom error objects aren't cloneable #29

jasnell opened this issue Jul 21, 2021 · 4 comments

Comments

@jasnell
Copy link

jasnell commented Jul 21, 2021

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.

@mcollina
Copy link
Member

Is this actionable for this module? How could we improve things?

@jasnell
Copy link
Author

jasnell commented Jul 21, 2021

It's likely more something just to document just in case. If you're not using custom errors at all then things should Just Work, but if any part of this is relying on things like a DOMException thrown from Node.js the results aren't going to be what you expect.

@mcollina
Copy link
Member

I would not think so, anyway let's keep this open and we'll see if it becomes a problem.

@davidmarkclements
Copy link
Member

you could provide an API for registering custom error constructors in the worker thread, then you'd have to somehow communicate that an error object that has entered the worker thread should be "recast" (Object.setPrototypeOf(CustomError.call(err), CustomError.prototype) ? )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants