Skip to content

Web-style worker error event always has a null error property #23473

@homomorphist

Description

@homomorphist

What version of Bun is running?

1.3.0+b0a6feca5

What platform is your computer?

Darwin 23.2.0 arm64 arm

What steps can reproduce the bug?

const src = `throw new Error("Hello, world!")`
const url = URL.createObjectURL(new Blob([src]))
const worker = new Worker(url)
worker.onerror = console.error

Observe that there isn't an Error present within the event, only a message (which happens to be large, containing more than one might expect from just a "message").

What is the expected behavior?

The error property shouldn't be null unless null was thrown or some other issue occurred while trying to retrieve data for that error.

Ideally, the error property would be contain was thrown.
This is what is done for node:worker_threads, though it dispatches the thrown value directly.

import { Worker } from 'node:worker_threads'
const worker = new Worker("meow", { eval: true })
worker.on("error", console.error)

Alternatively: the error property could be removed altogether, as it currently only serves to mislead.

What do you see instead?

An error event is logged, but there is no structured information about the error other than the message.

ErrorEvent {
  type: "error",
  message: "1 | throw new Error(\"Hello, world!\")\n              ^\nerror: Hello, world!\n      at blob:e2b6d5aa-958c-416b-bb23-3714ced689c0:1:11\n      at loadAndEvaluateModule (2:1)\n",
  error: null,
}

Additional information

This might be intentional, since web-style workers deliberately take a separate path to send the value as a message (#19509), but it's not clear to me why the value itself shouldn't be sent too.

If changed, this test would need to be updated.

You can extract info by parsing the message, but it varies in form quite a bit so it's flaky to do so.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Workeruses the web or node worker apibugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions