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

[worker_threads] make JS new Error() copyable across threads #26692

Closed
izelnakri opened this issue Mar 15, 2019 · 3 comments
Closed

[worker_threads] make JS new Error() copyable across threads #26692

izelnakri opened this issue Mar 15, 2019 · 3 comments
Labels
worker Issues and PRs related to Worker support.

Comments

@izelnakri
Copy link

izelnakri commented Mar 15, 2019

node version: v11.11.0

Today I have to normalize errors to send worker thread errors back to main thread:

parentPort.postMessage({ error: normalizeError(error) })

function normalizeError(errorObject) {
  return Object.keys(errorObject)
    .reduce((result, key) => Object.assign(result, { [key] : errorObject[key] }), {});
}
@addaleax addaleax added the worker Issues and PRs related to Worker support. label Mar 15, 2019
@addaleax
Copy link
Member

Hi!

One issue with this is that we’re following the HTML spec for structured cloning as far as message passing is concerned. Web specs generally don’t do breaking changes, and I think this would be a breaking change, although I’d personally love to see something like this.

(Fwiw, we have a rather complex implementation of error serialization for this reason as well.)

/cc @nodejs/workers

@amiller-gh
Copy link
Member

Updating this thread for posterity / paper trail.

There is movement on the spec / browser side for this. Since @addaleax's comment above the MDN article now calls out that Chrome does clone native Error objects, Firefox is working to implement, Safari has a bug open here, and the whatwg is tweaking spec semantics slightly to support.

@addaleax
Copy link
Member

Okay, I think that this can be closed then :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
worker Issues and PRs related to Worker support.
Projects
None yet
Development

No branches or pull requests

3 participants