Skip to content

Conversation

jonasgeiler
Copy link
Contributor

@jonasgeiler jonasgeiler commented Oct 17, 2025

A worker thread can throw anything via the throw keyword, which gets passed directly to 'error' event listeners. The event listener should not assume it is an Error object.

Here is a Node.js script proofing this:

import { isMainThread, Worker } from "node:worker_threads";

if (isMainThread) {
	// Main thread.

	const worker = new Worker(new URL(import.meta.url));

	worker.on("error", (err /* Documented as `Error`, but should be seen as `any`. */) => {
		console.log(typeof err); // Prints 'boolean'.
	});
} else {
	// Worker thread.

	throw false; // You can literally throw anything.
}

A worker thread can throw anything via the `throw` keyword, which gets passed directly to 'error' event listeners. The event listener should not assume it is an `Error` object.
@nodejs-github-bot nodejs-github-bot added doc Issues and PRs related to the documentations. worker Issues and PRs related to Worker support. labels Oct 17, 2025
@addaleax addaleax added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Oct 17, 2025
@aduh95 aduh95 merged commit 9fbf0cb into nodejs:main Oct 19, 2025
27 of 28 checks passed
@aduh95
Copy link
Contributor

aduh95 commented Oct 19, 2025

Landed in 9fbf0cb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. doc Issues and PRs related to the documentations. worker Issues and PRs related to Worker support.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants