Fix unchecked exception when Bun.plugin target cannot be converted to a string#31309
Fix unchecked exception when Bun.plugin target cannot be converted to a string#31309robobun wants to merge 1 commit into
Conversation
|
Warning Review limit reached
Your plan currently allows 1 review/hour. Refill in 58 minutes and 26 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 10:29 PM PT - May 23rd, 2026
❌ @robobun, your commit 08b10a8 has 4 failures in
🧪 To try this PR locally: bunx bun-pr 31309That installs a local version of the PR into your bun-31309 --bun |
There was a problem hiding this comment.
LGTM — straightforward exception-check fix matching the existing toWTFString + RETURN_IF_EXCEPTION pattern in this file.
Extended reasoning...
Overview
This PR touches a single code path in src/jsc/bindings/BunPlugin.cpp (setupBunPlugin), replacing toStringOrNull() on the target option with toWTFString() followed by RETURN_IF_EXCEPTION. Previously, when the conversion threw (e.g. target: Symbol()), toStringOrNull returned null, the validation block was skipped, and execution continued with a pending exception on the throw scope — tripping assertNoException() in debug/ASAN builds. The fix is 5 lines of code change plus an 11-line regression test in test/js/bun/plugin/plugins.test.ts.
Security risks
None. This is input validation for a runtime plugin option; the only effect is that an exception now propagates correctly to the caller as a TypeError instead of being left pending. No new data flow, parsing, auth, or filesystem behavior is introduced.
Level of scrutiny
Low. The change is mechanical and mirrors the exact idiom already used multiple times in the same file (e.g. namespaceValue.toWTFString(globalObject); RETURN_IF_EXCEPTION(scope, {}); in both onLoad and onResolve handlers). The non-exception path is semantically unchanged: values that previously stringified successfully and failed/passed the node|bun|browser check still behave identically, since toWTFString and toStringOrNull()->value() both go through ToString semantics.
Other factors
A targeted regression test was added directly adjacent to the existing "handles invalid 'target'" test, and the PR description confirms the full plugins.test.ts suite passes on a debug+ASAN build with BUN_JSC_validateExceptionChecks=1. The bug-hunting system found no issues, no CODEOWNERS apply to this path, and there are no outstanding human reviewer comments.
|
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 an unchecked JS exception in
Bun.plugin()(fuzzer-found, fingerprinte72b98fc73896e0c).setupBunPluginconverted thetargetoption to a string withtoStringOrNull(). When that conversion throws (e.g.targetis a Symbol, or an object whosetoStringreturns a Symbol), the code ignored the null result and continued with the exception still pending on the throw scope, eventually invoking the plugin'ssetupcallback. On debug/ASAN builds this tripsExceptionScope::assertNoException()and aborts:Repro:
The conversion now uses
toWTFString()withRETURN_IF_EXCEPTION, matching the rest of the file, so the exception propagates to the caller as a regularTypeErrorinstead of being swallowed while execution continues.How did you verify your code works?
TypeError: Cannot convert a symbol to a stringinstead of aborting (verified on a debug+ASAN build, including withBUN_JSC_validateExceptionChecks=1).test/js/bun/plugin/plugins.test.ts;bun bd test test/js/bun/plugin/plugins.test.tspasses (30 pass, 1 todo).