Skip to content
Closed
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
5 changes: 5 additions & 0 deletions changelog.d/9933-util-inspect-lazy-error-stack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### Fixed

- Materialize lazy Error stacks when `util.inspect()` formats an Error with a
`cause` or an `AggregateError` with `errors`, preserving Node-compatible
stack/body layout.
8 changes: 7 additions & 1 deletion crates/perry-runtime/src/builtins/formatting/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ unsafe fn format_error_headline(error_ptr: *const crate::error::ErrorHeader) ->
}

unsafe fn format_error_stack_frame(error_ptr: *const crate::error::ErrorHeader) -> Option<String> {
let stack = string_header_to_string((*error_ptr).stack, "");
// #9486 made Error stacks lazy: `ErrorHeader.stack` stays null until the
// first observable read materializes the captured frame payload. Inspect
// is one of those reads. Looking at the slot directly made Errors with a
// cause or AggregateError.errors print a standalone `{` where Node keeps
// it attached to the final stack line.
let stack_ptr = crate::error::materialize_error_stack(error_ptr.cast_mut());
let stack = string_header_to_string(stack_ptr, "");
stack
.lines()
.skip(1)
Expand Down
Loading