-
Notifications
You must be signed in to change notification settings - Fork 5k
fix(sql): don't crash in debug builds when bun:sql module load throws #34831
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import { expect, test } from "bun:test"; | ||
| import { bunEnv, bunExe } from "harness"; | ||
|
|
||
| test("Bun.SQL lazy getter propagates module load errors without crashing", async () => { | ||
| // The bun:sql internal module reads global `Symbol` at top level. If user | ||
| // code has clobbered the global before the first access, evaluating the | ||
| // module throws. That exception must propagate back to the caller as a | ||
| // normal JS error rather than crashing the process. | ||
| await using proc = Bun.spawn({ | ||
| cmd: [ | ||
| bunExe(), | ||
| "-e", | ||
| ` | ||
| globalThis.Symbol = "i"; | ||
| let caught = 0; | ||
| try { Bun.sql; } catch { caught++; } | ||
| try { Bun.SQL; } catch { caught++; } | ||
| console.log("caught=" + caught); | ||
| `, | ||
| ], | ||
| env: bunEnv, | ||
| stdout: "pipe", | ||
| stderr: "pipe", | ||
| }); | ||
|
|
||
| const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); | ||
|
|
||
| expect(stdout.trim()).toBe("caught=2"); | ||
| expect(stderr).toBe(""); | ||
| expect(exitCode).toBe(0); | ||
| }); | ||
Oops, something went wrong.
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.
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.
🟡 Per REVIEW.md, avoid asserting stderr is exactly empty — ASAN/debug builds can emit benign diagnostics that make this flake in CI. The
stdout === "caught=2"andexitCode === 0assertions already prove the process didn't crash and both exceptions were caught; consider dropping this line or asserting a combined{ stdout, exitCode }snapshot instead.Extended reasoning...
What the issue is
Line 29 asserts
expect(stderr).toBe(""). REVIEW.md's Tests reviewers reject section explicitly calls this out:Why it can flake
The test spawns
bunExe()withbunEnv.bunEnvsetsBUN_DEBUG_QUIET_LOGS=1, which suppresses Bun's own scoped debug loggers, but it does not suppress ASAN/UBSAN runtime diagnostics or other libc/loader warnings that can appear on stderr in the debug+ASAN CI lanes. When such a benign line appears,stderrbecomes non-empty and this assertion fails even though the behavior under test — the catchableTypeErrorpropagating out of theBun.sql/Bun.SQLlazy getters — is working correctly.Step-by-step
caught=2\nto stdout and exits 0 — the fix is working.expect(stdout.trim()).toBe("caught=2")passes.expect(stderr).toBe("")fails → spurious red CI.Why the existing assertions already suffice
The purpose of this test is to prove the process doesn't crash and that the module-load exception propagates as a catchable JS error. Both facts are fully established by:
stdout.trim() === "caught=2"→ bothtry { Bun.sql }andtry { Bun.SQL }threw and were caught.exitCode === 0→ no crash, no abort, no uncaught exception.The
stderr === ""assertion adds no additional signal — it only introduces flake risk.Suggested fix
Either drop line 29 entirely, or use the repo-conventional combined-object snapshot:
(If you want stderr visible in failure output for debugging, include it in the object but don't assert it's exactly empty.)
Severity
Marking as nit: this is a test-hygiene / potential-flake concern, not a correctness bug in the fix itself. The pattern also appears widely elsewhere in the test suite, so it's not uniquely blocking here — just worth aligning with the stated guideline while the file is new.