Title: [worker_threads]: Main thread receives Error object when the worker throws a primitive value · Issue #35506 · nodejs/node · GitHub
Open Graph Title: [worker_threads]: Main thread receives Error object when the worker throws a primitive value · Issue #35506 · nodejs/node
X Title: [worker_threads]: Main thread receives Error object when the worker throws a primitive value · Issue #35506 · nodejs/node
Description: Version: v14.7.0 Platform: Darwin suin 18.7.0 Darwin Kernel Version 18.7.0: Mon Feb 10 21:08:45 PST 2020; root:xnu-4903.278.28~1/RELEASE_X86_64 x86_64 Subsystem: N/A What steps will reproduce the bug? Summary: Since Node v14.7.0, when pr...
Open Graph Description: Version: v14.7.0 Platform: Darwin suin 18.7.0 Darwin Kernel Version 18.7.0: Mon Feb 10 21:08:45 PST 2020; root:xnu-4903.278.28~1/RELEASE_X86_64 x86_64 Subsystem: N/A What steps will reproduce the b...
X Description: Version: v14.7.0 Platform: Darwin suin 18.7.0 Darwin Kernel Version 18.7.0: Mon Feb 10 21:08:45 PST 2020; root:xnu-4903.278.28~1/RELEASE_X86_64 x86_64 Subsystem: N/A What steps will reproduce the b...
Opengraph URL: https://github.com/nodejs/node/issues/35506
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[worker_threads]: Main thread receives Error object when the worker throws a primitive value","articleBody":"\u003c!--\r\nThank you for reporting an issue.\r\n\r\nThis issue tracker is for bugs and issues found within Node.js core.\r\nIf you require more general support please file an issue on our help\r\nrepo. https://github.com/nodejs/help\r\n\r\n\r\nPlease fill in as much of the template below as you're able.\r\n\r\nVersion: output of `node -v`\r\nPlatform: output of `uname -a` (UNIX), or version and 32 or 64-bit (Windows)\r\nSubsystem: if known, please specify affected core module name\r\n-->\r\n\r\n* **Version**: v14.7.0\r\n* **Platform**: Darwin suin 18.7.0 Darwin Kernel Version 18.7.0: Mon Feb 10 21:08:45 PST 2020; root:xnu-4903.278.28~1/RELEASE_X86_64 x86_64\r\n* **Subsystem**: N/A\r\n\r\n### What steps will reproduce the bug?\r\n\r\nSummary: Since Node v14.7.0, when primitive values are thrown in a worker, the main thread receives it as Error objects.\r\n\r\nI'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.\r\n\r\n```js\r\n// main.js\r\nconst { Worker } = require('worker_threads')\r\nconst worker = new Worker('./worker.js')\r\nconsole.log(process.versions.node)\r\nworker.on('error', err => {\r\n console.error(err)\r\n})\r\n```\r\n\r\n```js\r\n// worker.js\r\nthrow 'Error was thrown in worker'\r\n```\r\n\r\nin Node v14.6.0:\r\n\r\n```\r\n$ node main.js\r\n14.6.0\r\nError was thrown in worker\r\n```\r\n\r\nin Node v14.7.0:\r\n\r\n```\r\n$ node main.js\r\n14.7.0\r\nError [ERR_UNHANDLED_ERROR]: Unhandled error. ('Error was thrown in worker')\r\n at process.emit (events.js:303:17)\r\n at emitUnhandledRejectionOrErr (internal/event_target.js:541:11)\r\n at MessagePort.[nodejs.internal.kHybridDispatch] (internal/event_target.js:356:9)\r\n at MessagePort.exports.emitMessage (internal/per_context/messageport.js:18:26) {\r\n code: 'ERR_UNHANDLED_ERROR',\r\n context: 'Error was thrown in worker'\r\n}\r\n```\r\n\r\nOther primitives:\r\n\r\n\u003cdetails>\r\n\r\n__Undefined__\r\n\r\n```js\r\n// worker.js\r\nthrow undefined\r\n```\r\n\r\n```\r\n$ node main.js\r\n14.6.0\r\nundefined\r\n\r\n$ node main.js\r\n14.7.0\r\nError [ERR_UNHANDLED_ERROR]: Unhandled error. (undefined)\r\n at process.emit (events.js:303:17)\r\n at emitUnhandledRejectionOrErr (internal/event_target.js:541:11)\r\n at MessagePort.[nodejs.internal.kHybridDispatch] (internal/event_target.js:356:9)\r\n at MessagePort.exports.emitMessage (internal/per_context/messageport.js:18:26) {\r\n code: 'ERR_UNHANDLED_ERROR',\r\n context: undefined\r\n}\r\n```\r\n\r\n__Number__\r\n\r\n```js\r\n// worker.js\r\nthrow 0\r\n```\r\n\r\n```\r\n$ node main.js\r\n14.6.0\r\n0\r\n\r\n$ node main.js\r\n14.7.0\r\nError [ERR_UNHANDLED_ERROR]: Unhandled error. (0)\r\n at process.emit (events.js:303:17)\r\n at emitUnhandledRejectionOrErr (internal/event_target.js:541:11)\r\n at MessagePort.[nodejs.internal.kHybridDispatch] (internal/event_target.js:356:9)\r\n at MessagePort.exports.emitMessage (internal/per_context/messageport.js:18:26) {\r\n code: 'ERR_UNHANDLED_ERROR',\r\n context: 0\r\n}\r\n```\r\n\r\n__Symbol__\r\n\r\n```js\r\n// worker.js\r\nthrow Symbol('this is a symbol')\r\n```\r\n\r\n```\r\n$ node main.js\r\n14.6.0\r\nSymbol(this is a symbol)\r\n\r\n$ node main.js\r\n14.7.0\r\nError [ERR_UNHANDLED_ERROR]: Unhandled error. (Symbol(this is a symbol))\r\n at process.emit (events.js:303:17)\r\n at emitUnhandledRejectionOrErr (internal/event_target.js:541:11)\r\n at MessagePort.[nodejs.internal.kHybridDispatch] (internal/event_target.js:356:9)\r\n at MessagePort.exports.emitMessage (internal/per_context/messageport.js:18:26)\r\n```\r\n\r\n\u003c/details>\r\n\r\n\r\n\r\n\r\n\r\n\r\n### How often does it reproduce? Is there a required condition?\r\n\r\nThere is no condition.\r\n\r\n### What is the expected behavior?\r\n\r\nI'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.\r\n\r\n### What do you see instead?\r\n\r\nThe main thread gets the Error object.\r\n\r\n### Additional information\r\n\r\n\u003c!--\r\nTell us anything else you think we should know.\r\n-->\r\n","author":{"url":"https://github.com/suin","@type":"Person","name":"suin"},"datePublished":"2020-10-05T15:23:18Z","url":"https://github.com/nodejs/node/issues/35506"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:7a6d092a-f94a-1d72-48c9-b0a0c7f5c44b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E154:36D84F:9791AC:C9B3AD:6AED30C5 |
| html-safe-nonce | 8c5401d55c7b8e3ddc9a9ed4c85c9aa332b20ecb1499249f50556456799c7700 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMTU0OjM2RDg0Rjo5NzkxQUM6QzlCM0FEOjZBRUQzMEM1IiwidmlzaXRvcl9pZCI6IjI2NjkxMjY3MTIyOTYyODg0NTMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 9cb52145284de70df925f43eed7b24d6e58055ab0a7f745f070a55fa77715772 |
| hovercard-subject-tag | issue:714938145 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/35506/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9a7263c615df6368bfe5ed82185ea697191e8abf3bcff40ddd059cf4cd769115/nodejs/node/issues/35506 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9a7263c615df6368bfe5ed82185ea697191e8abf3bcff40ddd059cf4cd769115/nodejs/node/issues/35506 |
| og:image:alt | Version: v14.7.0 Platform: Darwin suin 18.7.0 Darwin Kernel Version 18.7.0: Mon Feb 10 21:08:45 PST 2020; root:xnu-4903.278.28~1/RELEASE_X86_64 x86_64 Subsystem: N/A What steps will reproduce the b... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | suin |
| hostname | github.com |
| expected-hostname | github.com |
| None | e51d0b7b5ab34b1688c05b54c3ed17b8658b2fa9bca973a9c740683ccb12cf4a |
| turbo-cache-control | no-preview |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 59ebb7b901cc154ecc179a44f266fcf69f343b30 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width