fix(Bun.plugin): propagate exception thrown while converting 'target' to a string#31390
fix(Bun.plugin): propagate exception thrown while converting 'target' to a string#31390robobun wants to merge 1 commit into
Conversation
… to a string Bun.plugin() converted the 'target' option to a string with toStringOrNull() and ignored the case where the conversion throws (e.g. a Symbol.toPrimitive that returns an object). The pending exception was then carried into subsequent JSC calls, failing the assertNoException assertion in debug builds. Use toWTFString() and return early if the conversion throws.
|
Warning Review limit reached
Your plan includes 5 reviews of capacity. Refill in 16 minutes and 39 seconds. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more review capacity refills, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than trial, open-source, and free plans. In all cases, review capacity refills continuously over time. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
Comment |
|
Updated 4:47 AM PT - May 25th, 2026
❌ @robobun, your commit ab9fd78 has 1 failures in
🧪 To try this PR locally: bunx bun-pr 31390That installs a local version of the PR into your bun-31390 --bun |
There was a problem hiding this comment.
LGTM — straightforward exception-propagation fix matching the existing toWTFString + RETURN_IF_EXCEPTION pattern used elsewhere in this file, with a regression test.
Extended reasoning...
Overview
This PR changes 6 lines in setupBunPlugin() (src/jsc/bindings/BunPlugin.cpp) to convert the target option via toWTFString() + RETURN_IF_EXCEPTION instead of toStringOrNull() with no exception check. It adds a 15-line regression test in test/js/bun/plugin/plugins.test.ts.
The previous code called toStringOrNull(), which returns nullptr when ToString throws (e.g., a Symbol.toPrimitive that returns an object), and then silently fell through with a pending exception into constructEmptyObject / call(setup, ...), tripping assertNoException in debug builds. The new code returns early on the exception, which is the correct JSC idiom and exactly mirrors how namespaceValue.toWTFString(globalObject) and moduleIdValue.toWTFString(globalObject) are handled elsewhere in the same file.
Security risks
None. This is purely an exception-handling correctness fix on a validation-only code path (the converted targetString is only compared against "node"/"bun"/"browser" and never stored or used afterward). No new attack surface, no auth/crypto/permissions involvement.
Level of scrutiny
Low. The diff is tiny, mechanical, and follows an established pattern repeated throughout BunPlugin.cpp. The only behavioral change is that an exception thrown during target stringification now surfaces immediately instead of being carried into later calls — strictly a correctness improvement. The success path (valid string target) is semantically unchanged since both toStringOrNull and toWTFString invoke the same ToString abstract operation.
Other factors
- The bug-hunting system found no issues.
- A focused regression test was added next to the existing "handles invalid 'target'" test and the author reports the full test file passes (30/0) plus a clean
BUN_JSC_validateExceptionChecks=1run. - No CODEOWNERS entry covers these paths.
- No prior reviewer comments are outstanding.
|
This PR may be a duplicate of:
🤖 Generated with Claude Code |
|
Closing as a duplicate of #31286, which fixes the same unchecked exception in |
What does this PR do?
Fixes a debug assertion failure (
ASSERTION FAILED: Unexpected exception observed ... !exception()inExceptionScope::assertNoException) found by fuzzing, fingerprint34a19a3501a83cae.Bun.plugin()converted thetargetoption to a string withtoStringOrNull()and silently ignored the case where the conversion throws — for example whentargetis an object whoseSymbol.toPrimitivereturns an object. The pendingTypeError: Symbol.toPrimitive returned an objectwas then carried into the subsequent object construction and thesetup()call, trippingassertNoExceptionin debug builds (and invokingsetup()with a pending exception in release builds).The fix converts
targetwithtoWTFString()and returns early if the conversion throws, matching how the rest ofBunPlugin.cpphandles string conversions.Repro that crashed before:
Now it throws
TypeError: Symbol.toPrimitive returned an objectinstead.How did you verify your code works?
TypeError.test/js/bun/plugin/plugins.test.ts(errors > handles a 'target' that throws while being converted to a string); ran the full file withbun bd test test/js/bun/plugin/plugins.test.ts— 30 pass, 0 fail.BUN_JSC_validateExceptionChecks=1that no unchecked-exception warnings are reported on this path.