-
Notifications
You must be signed in to change notification settings - Fork 3.9k
fix: use JSONParseWithException for proper error handling #25881
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
Conversation
|
Updated 5:37 PM PT - Jan 7th, 2026
❌ Your commit
🧪 To try this PR locally: bunx bun-pr 25881That installs a local version of the PR into your bun-25881 --bun |
WalkthroughThe SQLClient.cpp file was updated to use JSONParseWithException instead of JSONParse within the DataCellTag::Json code path, improving exception handling for JSON parsing operations without modifying public API signatures. Changes
Suggested reviewers
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Disabled knowledge base sources:
📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (1)src/bun.js/bindings/**/*.cpp📄 CodeRabbit inference engine (CLAUDE.md)
Files:
🧠 Learnings (6)📓 Common learnings📚 Learning: 2025-09-25T22:07:13.851ZApplied to files:
📚 Learning: 2025-12-16T00:21:32.179ZApplied to files:
📚 Learning: 2025-12-16T00:21:32.179ZApplied to files:
📚 Learning: 2025-11-24T18:37:47.899ZApplied to files:
📚 Learning: 2025-11-24T18:36:59.706ZApplied to files:
Comment |
Fix bug where RETURN_IF_EXCEPTION after JSONParse would never trigger on JSON parse failure since JSONParse doesn't throw. JSONParse returns an empty JSValue on failure without throwing, so RETURN_IF_EXCEPTION will not catch parsing errors. JSONParseWithException properly throws a SyntaxError which RETURN_IF_EXCEPTION can catch. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
e7ce2be to
6414524
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/bun.js/bindings/SQLClient.cpp (1)
188-196: The SQLClient.cpp fix is correct, but verification found an additional location with the same unfixed pattern.The change from
JSONParsetoJSONParseWithExceptionin SQLClient.cpp (line 191) correctly addresses the bug whereRETURN_IF_EXCEPTIONwould never trigger on JSON parse failures—sinceJSONParsereturns an empty JSValue without throwing, whileJSONParseWithExceptionproperly throws a SyntaxError that the exception handler can catch.However, verification found the same unfixed pattern in
src/bun.js/modules/BunJSCModule.hat lines 671–674:JSValue stackTraces = JSONParse(globalObject, samplingProfiler.stackTracesAsJSON()->toJSONString()); // ... code ... RETURN_IF_EXCEPTION(throwScope, {});This location was modified in the same commit but still contains the original bug. Apply the same fix: replace
JSONParsewithJSONParseWithExceptionto ensure parse errors are properly thrown and caught.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
src/bun.js/bindings/SQLClient.cpp
🧰 Additional context used
📓 Path-based instructions (1)
src/bun.js/bindings/**/*.cpp
📄 CodeRabbit inference engine (CLAUDE.md)
src/bun.js/bindings/**/*.cpp: Create classes in three parts in C++ when there is a public constructor: Foo (JSDestructibleObject), FooPrototype (JSNonFinalObject), and FooConstructor (InternalFunction)
Define properties using HashTableValue arrays in C++ JavaScript class bindings
Add iso subspaces for C++ classes with fields in JavaScript class bindings
Cache structures in ZigGlobalObject for JavaScript class bindings
Files:
src/bun.js/bindings/SQLClient.cpp
🧠 Learnings (6)
📓 Common learnings
Learnt from: cirospaciari
Repo: oven-sh/bun PR: 22946
File: test/js/sql/sql.test.ts:195-202
Timestamp: 2025-09-25T22:07:13.851Z
Learning: PR oven-sh/bun#22946: JSON/JSONB result parsing updates (e.g., returning parsed arrays instead of legacy strings) are out of scope for this PR; tests keep current expectations with a TODO. Handle parsing fixes in a separate PR.
📚 Learning: 2025-09-25T22:07:13.851Z
Learnt from: cirospaciari
Repo: oven-sh/bun PR: 22946
File: test/js/sql/sql.test.ts:195-202
Timestamp: 2025-09-25T22:07:13.851Z
Learning: PR oven-sh/bun#22946: JSON/JSONB result parsing updates (e.g., returning parsed arrays instead of legacy strings) are out of scope for this PR; tests keep current expectations with a TODO. Handle parsing fixes in a separate PR.
Applied to files:
src/bun.js/bindings/SQLClient.cpp
📚 Learning: 2025-12-16T00:21:32.179Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-16T00:21:32.179Z
Learning: Applies to src/bun.js/bindings/**/*.cpp : Add iso subspaces for C++ classes with fields in JavaScript class bindings
Applied to files:
src/bun.js/bindings/SQLClient.cpp
📚 Learning: 2025-12-16T00:21:32.179Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-16T00:21:32.179Z
Learning: Applies to src/bun.js/bindings/**/*.cpp : Define properties using HashTableValue arrays in C++ JavaScript class bindings
Applied to files:
src/bun.js/bindings/SQLClient.cpp
📚 Learning: 2025-11-24T18:37:47.899Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: src/bun.js/bindings/v8/AGENTS.md:0-0
Timestamp: 2025-11-24T18:37:47.899Z
Learning: Applies to src/bun.js/bindings/v8/**/<UNKNOWN> : <UNKNOWN>
Applied to files:
src/bun.js/bindings/SQLClient.cpp
📚 Learning: 2025-11-24T18:36:59.706Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: src/bun.js/bindings/v8/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:36:59.706Z
Learning: Applies to src/bun.js/bindings/v8/V8*.h : Create V8 class headers with .h extension following the pattern V8ClassName.h that include pragma once, v8.h, V8Local.h, V8Isolate.h, and declare classes extending from Data with BUN_EXPORT static methods
Applied to files:
src/bun.js/bindings/SQLClient.cpp
Summary
RETURN_IF_EXCEPTIONafterJSONParsewould never trigger on JSON parse failure sinceJSONParsedoesn't throwJSONParseWithExceptioninstead of manually checking for empty result and throwingDetails
JSC::JSONParsereturns an emptyJSValueon failure without throwing an exception. This means thatRETURN_IF_EXCEPTION(scope, {})will never catch JSON parsing errors when used afterJSONParse.Before this fix in
SQLClient.cpp:This could cause issues when parsing invalid JSON data from SQL databases (e.g., PostgreSQL's JSON/JSONB columns).
JSONParseWithExceptionproperly throws aSyntaxErrorexception thatRETURN_IF_EXCEPTIONcan catch.Test plan
bun bdModuleLoader.cppandBunObject.cpp🤖 Generated with Claude Code