Skip to content

Error stack GC finalizer: render only frame lines, add the name/message header at materialization - #302

Closed
robobun wants to merge 2 commits into
mainfrom
error-info-with-instance
Closed

Error stack GC finalizer: render only frame lines, add the name/message header at materialization#302
robobun wants to merge 2 commits into
mainfrom
error-info-with-instance

Conversation

@robobun

@robobun robobun commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

ErrorInstance::finalizeUnconditionally caches the stack string when captured frames die, through VM::onComputeErrorInfo, which cannot include the error name and message: the instance must not be read during the GC end phase (even an own-property lookup can re-materialize a property table, which allocates). The cached string began with a bare "Error" and a later .stack access served it as-is.

This adds VM::onComputeErrorInfoFrames, preferred over onComputeErrorInfo when set, with the contract that it renders only the frame lines. A new ErrorInstance bit records that the cached string needs a header, and materializeErrorInfoIfNeeded prepends sanitizedToString() when publishing it, where the instance is live and allocation is allowed. Nothing touches the instance inside the finalizer.

This also keeps the header lazy (a name assigned between the GC and the first .stack read is reflected, like the first-access path), and non-string name/message values render the same on both paths.

The existing callbacks keep their signatures and behavior; embedders that do not register the new callback are unaffected.

Needed for oven-sh/bun#34398.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants