Skip to content
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

Uncaught exceptions from webworkers started by tests in browser runner not shown properly #7440

Open
6 tasks done
jbms opened this issue Feb 6, 2025 · 1 comment
Open
6 tasks done
Labels
feat: browser Issues and PRs related to the browser runner p2-to-be-discussed Enhancement under consideration (priority) pending triage

Comments

@jbms
Copy link

jbms commented Feb 6, 2025

Describe the bug

When using the browser runner, if a test starts a webworker, and that webworker throws an uncaught exception, instead of the exception being properly printed with other test output, it gets shown as stderr output of "null" with no easy way to track down the source of it.

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-oszejgfz?file=test%2Fbasic.test.ts

System Info

N/A

See stackblitz.

Used Package Manager

npm

Validations

@hi-ogawa
Copy link
Contributor

hi-ogawa commented Feb 7, 2025

For comparison, here is node worker thread equivalent, which surfaces worker error as unhandled error on main thread https://stackblitz.com/edit/vitest-dev-vitest-izjedp5s?file=test%2Fbasic.test.ts

I think this is a fundamental difference for how error are serialized back to main thread on browser and on node, so I'm not sure there's anything we can do.

Probably the reason why null shows up but not causing "unhandled error test failure" is because null is specifically skipped here.

function throwUnhandlerError(e: ErrorEvent) {
if (userErrorListenerCount === 0 && e.error != null) {
cb(e)
}
else {
console.error(e.error)
}
}

If you want to resurface worker error as test unhandled errort, this might be possible in user land at least.
https://stackblitz.com/edit/vitest-dev-vitest-w4jcm4z1?file=test%2Fbasic.test.ts

  worker.onerror = (e) => {
    e.stopImmediatePropagation(); // skip `window.on("error" ...)`
    console.error('worker.onerror', e.error);
    throw new Error("Worker error", { cause: e })
  };

@hi-ogawa hi-ogawa added the feat: browser Issues and PRs related to the browser runner label Feb 7, 2025
@hi-ogawa hi-ogawa moved this to P2 - 2 in Team Board Feb 11, 2025
@hi-ogawa hi-ogawa added the p2-to-be-discussed Enhancement under consideration (priority) label Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: browser Issues and PRs related to the browser runner p2-to-be-discussed Enhancement under consideration (priority) pending triage
Projects
Status: P2 - 2
Development

No branches or pull requests

2 participants