feat(runtime): show the actual error when an async job throws#13
feat(runtime): show the actual error when an async job throws#13wytzepiet wants to merge 1 commit into
Conversation
JsAsyncRuntime::execute_pending_job mapped rquickjs's AsyncJobException straight through anyhow, but that type's Display is the opaque "Async job raised an exception" — the actual JS error and stack are left on the offending context for the caller to recover (per its docs) and were thrown away. A host pumping the job queue (e.g. draining microtasks after a bridge call) only saw that opaque string plus a Rust backtrace, which is useless for diagnosing a JS-level failure such as an unhandled promise rejection. Recover the pending exception from the job's context (the same way the runtime's own idle() does) and include its message/stack in the returned error, so the host sees the real reason. Additive: signature unchanged; only the error detail improves. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Review findings:
Verification run on this PR: |
When a queued job (a promise callback, a
setTimeout, etc.) throws,executePendingJobreported just:The real JavaScript error — its message and stack — was thrown away, so you couldn't tell what actually broke.
Here's why: rquickjs hands back an
AsyncJobExceptionwhose text is exactly that fixed string. The real error is left on the job's context for the caller to read withCtx::catch(as its docs note). fjs just wasn't reading it.This change reads it — the same way the runtime's own
idle()already does — and puts it in the error. So now you get the real thing:Reading the error also clears it, which fixes a small side bug: the old code left the exception pending, so it could show up again on the next
executePendingJobcall.The method signature doesn't change — only the error text gets better.
🤖 Generated with Claude Code