-
Notifications
You must be signed in to change notification settings - Fork 5k
console.takeHeapSnapshot: report snapshot parse failures instead of aborting #37070
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
Open
robobun
wants to merge
4
commits into
main
Choose a base branch
from
farm/03035019/console-take-heap-snapshot-exceptions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
88419b2
console: propagate heap snapshot JSONParse failures instead of asserting
robobun 3562d82
console: report snapshot formatting failures instead of leaving them …
robobun 7a093db
console.takeHeapSnapshot: make the failure path testable and fix the …
robobun 56cf03b
ci: retrigger
robobun 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
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,54 @@ | ||
| import { describe, expect, it } from "bun:test"; | ||
| import { bunEnv, bunExe } from "harness"; | ||
|
|
||
| describe.concurrent("console.takeHeapSnapshot", () => { | ||
| it("prints the parsed snapshot and survives BUN_JSC_validateExceptionChecks", async () => { | ||
| // JSONParse of the snapshot JSON can throw (out of memory building the | ||
| // parse tree), so the binding must hand the exception back to the console | ||
| // hook instead of releaseAssertNoException()-crashing, and the hook must | ||
| // report it rather than leave it pending under JSC's | ||
| // consoleProtoFuncTakeHeapSnapshot, whose scope performs no exception | ||
| // check after the client call. validateExceptionChecks aborts on debug | ||
| // builds if any scope is left unchecked; on release builds the option is | ||
| // a no-op and this just exercises the snapshot path. | ||
| await using proc = Bun.spawn({ | ||
| cmd: [bunExe(), "-e", `console.takeHeapSnapshot(); console.takeHeapSnapshot("label"); console.log("done");`], | ||
| env: { ...bunEnv, BUN_JSC_validateExceptionChecks: "1" }, | ||
| stdout: "pipe", | ||
| stderr: "pipe", | ||
| }); | ||
| const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); | ||
| const uncheckedScopes = stderr | ||
| .split("\n") | ||
| .map(line => line.trim()) | ||
| .filter(line => line.startsWith("This scope can throw") || line.startsWith("But the exception was unchecked")); | ||
| expect(stdout).toContain(`type: "Inspector"`); | ||
| expect(stdout.endsWith("done\n")).toBe(true); | ||
| expect(uncheckedScopes).toEqual([]); | ||
| expect(exitCode).toBe(0); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| }); | ||
|
|
||
| it("propagates exceptions thrown while coercing the label", async () => { | ||
| // The label toString runs before the snapshot is taken; the console | ||
| // function checks for the exception and rethrows it. | ||
| await using proc = Bun.spawn({ | ||
| cmd: [ | ||
| bunExe(), | ||
| "-e", | ||
| `try { | ||
| console.takeHeapSnapshot({ toString() { throw new Error("boom"); } }); | ||
| console.log("did not throw"); | ||
| } catch (e) { | ||
| console.log("caught:", e.message); | ||
| }`, | ||
| ], | ||
| env: { ...bunEnv, BUN_JSC_validateExceptionChecks: "1" }, | ||
| stdout: "pipe", | ||
| stderr: "pipe", | ||
| }); | ||
| const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); | ||
| expect(stdout).toBe("caught: boom\n"); | ||
| expect(stderr).toBe(""); | ||
| expect(exitCode).toBe(0); | ||
| }); | ||
| }); | ||
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.
Uh oh!
There was an error while loading. Please reload this page.