Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/jsc/bindings/FormatStackTraceForJS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,10 @@ JSC::JSValue computeErrorInfoWrapperToJSValue(JSC::VM& vm, Vector<StackFrame>& s
line_in = line.oneBasedInt();
column_in = column.oneBasedInt();

// materializeErrorInfoIfNeeded putDirect()s this unconditionally; an empty JSValue
// in property storage crashes the next read. https://github.com/oven-sh/bun/issues/34095
if (!result) [[unlikely]]
return jsUndefined();
return result;
}

Expand Down
24 changes: 24 additions & 0 deletions test/js/node/v8/capture-stack-trace.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1003,3 +1003,27 @@ test("printing an error whose message getter calls Error.captureStackTrace on it

expect({ lastLine: stdout.trimEnd().split("\n").pop(), exitCode }).toEqual({ lastLine: "after", exitCode: 0 });
});

// https://github.com/oven-sh/bun/issues/34095
test("lazy error-info materialization does not store an empty stack value when the compute hook throws", async () => {
const src = `
Error.prepareStackTrace = (e, s) => "custom-stack";
const e = new Error("x");
Object.defineProperty(e, "message", { get() { throw new TypeError("msg-boom"); } });
let first = "no-throw";
try { void e.stack; } catch (err) { first = err.message; }
console.log(JSON.stringify({ first, secondType: typeof e.stack }));
`;
await using proc = Bun.spawn({
cmd: [bunExe(), "-e", src],
env: bunEnv,
stdout: "pipe",
stderr: "pipe",
});
const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);
expect({ stdout: stdout.trim(), signalCode: proc.signalCode }).toEqual({
stdout: JSON.stringify({ first: "msg-boom", secondType: "undefined" }),
signalCode: null,
});
expect(exitCode).toBe(0);
});
Loading