node:worker_threads: new Worker() validates options.name before the filename, execArgv, argv and env
What version of Bun is running?
1.4.3-canary.1+367d939d9. A debug build of main a4f1429148 gives the same four lines.
What platform is your computer?
Linux x64
What steps can reproduce the bug?
Each call has two invalid options. One of them is name. Run the script with bun and with node:
const { Worker } = require("node:worker_threads");
function attempt(label, create) {
try {
create().terminate();
console.log(label, "no error");
} catch (e) {
console.log(label, e.code, JSON.stringify(e.message.slice(0, 62)));
}
}
attempt("name + filename:", () => new Worker("foo", { name: {} }));
attempt("name + execArgv:", () => new Worker("1", { eval: true, name: {}, execArgv: 1 }));
attempt("name + argv: ", () => new Worker("1", { eval: true, name: {}, argv: 1 }));
attempt("name + env: ", () => new Worker("1", { eval: true, name: {}, env: 1 }));What is the expected behavior?
Node v26.3.0 validates options.name last. The error is for the other option:
name + filename: ERR_WORKER_PATH "The worker script or module filename must be an absolute path "
name + execArgv: ERR_INVALID_ARG_TYPE "The \"options.execArgv\" property must be an instance of Array. "
name + argv: ERR_INVALID_ARG_TYPE "The \"options.argv\" property must be an instance of Array. Rece"
name + env: ERR_INVALID_ARG_TYPE "The \"options.env\" property must be of type object or one of un"What do you see instead?
Bun validates options.name first. The error is always for name:
name + filename: ERR_INVALID_ARG_TYPE "The \"options.name\" property must be of type string. Received a"
name + execArgv: ERR_INVALID_ARG_TYPE "The \"options.name\" property must be of type string. Received a"
name + argv: ERR_INVALID_ARG_TYPE "The \"options.name\" property must be of type string. Received a"
name + env: ERR_INVALID_ARG_TYPE "The \"options.name\" property must be of type string. Received a"Additional information
Node validates in this order: execArgv, argv, the filename, env, name (lib/internal/worker.js#L217-L284).
In Bun, the Worker constructor in src/js/node/worker_threads.ts calls normalizeWorkerName(options.name) before it looks at the filename. The native constructor (src/jsc/bindings/webcore/JSWorker.cpp) validates env, argv and execArgv after that.
A call with one invalid option gives the same error in both runtimes. Only the error for a call with two or more invalid options is different.
Source: oven-sh/bun