-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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]: Main thread receives Error object when the worker throws a primitive value #35506
Comments
Interestingly, when using const { Worker } = require('worker_threads');
console.log(process.versions.node);
new Worker(new URL('data:text/javascript,throw 4')).on('error', err => {
console.error(err);
}); $ node main.js
15.0.0-pre
4 |
Looks like a consequence of 0aa3809b6b - i don't think this should be expected behavior but @addaleax can maybe confirm? |
Right – this should not be happening, it’s a bug 👍 |
Ok, so basically the problem here is that, because the main script inside a Worker is started from within a I basically see 2 ways to solve this:
In particular, this did not just change the behavior for the main script unintentionally, but also for exceptions thrown inside any @jasnell @benjamingr Thoughts? |
ping @jasnell @benjamingr any further thoughts? I’d lean towards option 2, if nobody has a strong opinion. |
I lean towards option #2 as well with no strong opinions. |
Missed the original ping on this... no strong opinions on either option. |
This is not coming in current master, should we go ahead and create a minor version patch for this? |
@yashLadha do you mind clarifying what you mean by that? |
@benjamingr I meant to say that if this issue exists in an older version of node we can backport the fix to that tree, if it feels viable. |
@yashLadha was this issue actually resolved in master? I don't see any PRs or work relating to it. |
Any update on this that you know about? I've encountered an issue when handling errors thrown within a worker thread in v20 |
What steps will reproduce the bug?
Summary: Since Node v14.7.0, when primitive values are thrown in a worker, the main thread receives it as Error objects.
I'm not sure this is actually a bug. But I couldn't find out the information about this breaking change. So I have created this issue. If this is an expected change, please close this issue.
in Node v14.6.0:
in Node v14.7.0:
Other primitives:
Undefined
Number
Symbol
How often does it reproduce? Is there a required condition?
There is no condition.
What is the expected behavior?
I'm not sure which is valid behavior, but at point of view of backward compatibilities, it would be the expected behavior that the main thread receives the unhandled primitive error as the primitive value instead of the Error object like the Node v14.6.0 behavior.
What do you see instead?
The main thread gets the Error object.
Additional information
The text was updated successfully, but these errors were encountered: