-
Notifications
You must be signed in to change notification settings - Fork 5k
Bun__inspect: don't panic when user JS throws during error-message formatting #30980
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -720,7 +720,14 @@ pub fn bun_inspect(global_this: &JSGlobalObject, value: JSValue) -> BunString { | |
| let mut array: Vec<u8> = Vec::new(); | ||
|
|
||
| let mut formatter = ConsoleObject::Formatter::new(global_this); | ||
| if write!(&mut array, "{}", value.to_fmt(&mut formatter)).is_err() { | ||
| use core::fmt::Write; | ||
| if write!( | ||
| bun_core::fmt::VecWriter(&mut array), | ||
| "{}", | ||
| value.to_fmt(&mut formatter) | ||
| ) | ||
| .is_err() | ||
| { | ||
|
Comment on lines
+724
to
+730
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟣 🟣 Heads up (pre-existing): there is one more instance of this same Extended reasoning...SummaryThis is a third site (in addition to This is pre-existing: the PR does not touch Code path
Because only Why nothing prevents itThe Step-by-step proofimport { expect, test } from "bun:test";
expect.extend({
myMatcher(received) {
return { pass: false, message: () => this.utils.printReceived(received) };
},
});
const bad = { [Symbol.for("nodejs.util.inspect.custom")]() { throw new Error("boom"); } };
test("x", () => expect(bad).myMatcher());
ImpactA user-supplied object with a throwing custom inspect, passed to a custom matcher that uses Suggested fixSame as |
||
| return BunString::empty(); | ||
| } | ||
| BunString::clone_utf8(&array) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.