[v8-bridge] surface unhandled promise rejections via cs_v8_last_error#634
Merged
[v8-bridge] surface unhandled promise rejections via cs_v8_last_error#634
Conversation
Contributor
Benchmark Results (Linux x86-64)
CLI Tool Benchmarks
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Before
Unhandled promise rejections in
@chadscript: interpretpragma code vanished silently. A script likenew Promise((_, rej) => rej("boom"))with no.catch()would run,SpinEventLoopwould drain, andcs_v8_last_errorstayed empty — the caller treated the script as successful.After
V8's
PromiseRejectCallbackis wired on isolate init. Unhandled rejections (eventkPromiseRejectWithNoHandler— specifically ignoring thekPromiseHandlerAddedAfterRejectfalse-positive) are captured into a thread-local. AfterSpinEventLoopreturns, bothrun_scriptandcs_v8_eval_script_nodepropagate the captured rejection intot_last_errorand fail the call socs_v8_last_errorreads it like any synchronous throw.Description
~49 LOC, all in
c_bridges/node-bridge.cc:thread_local t_last_unhandled_rejectionseparate fromt_last_errorso a sync throw isn't clobbered.SetPromiseRejectCallbackinstalled incs_node_lazy_initright after the Environment is set up.kPromiseRejectWithNoHandler, stringifies the rejection value.SpinEventLoop.Follows the same per-call-clear → run → check-after pattern as existing
try_catcherror handling.Test plan
vendor/node/+ libnode toolchain. My worktree doesn't have it; node-bridge.cc isn't compiled in CI either (no libnode step inci.yml). Anyone with libnode locally can run a pragma file that rejects without.catchand observe thatcs_v8_last_errornow returns the rejection string instead of empty.tests/fixtures/pragma-interpret/that asserts a pragma file with an unhandled rejection fails with the expected message (once pragma test infra exists).Closes #617.
Next steps / Gaps
pragma-interpret/test category once the pragma+libnode path has a CI lane.kPromiseHandlerAddedAfterRejectis ignored so a late.catch()doesn't trip the error — but Node's process-levelunhandledRejectionevent is NOT forwarded; if a Node handler is attached, V8 still fires thekPromiseRejectWithNoHandlerevent before the handler sees it. Cleaner integration would route throughprocess.on('unhandledRejection')instead.