Skip to content

Backtraces: record the call chain when an exception is raised - #516

Merged
stevedekorte merged 1 commit into
masterfrom
backtraces
Nov 17, 2026
Merged

stevedekorte merged 1 commit into
masterfrom
backtraces

Conversation

@stevedekorte

Copy link
Copy Markdown
Member

Uncaught errors printed "nothing on stack" for nearly every error. The backtrace was built from Call objects on the retain stack, which the stackless evaluator no longer leaves there, and the frames are unwound before anything prints.

Now

  Exception: argument 0 to method '+' must be a Number, not a 'nil'
  ---------
  Number +                             bt4.io 13
  Number qux                           bt4.io 8
  Foo baz                              bt4.io 3
  Foo bar                              bt4.io 16
  Object run                           bt4.io 17

How

  • IoState_recordStackTraceOn_ walks the frame chain when an exception is raised (from IoState_error_ and Coroutine rawSignalException) and stores a flat list on the exception: the raising frame, then each frame waiting on a method or block it called. Capped at 64 entries.
  • Exception stackTraceLines formats it and drops the VM's own raising steps and the host's frames (CLI, browser eval). Coroutine backTraceString prints it.
  • pass keeps the original trace.
  • When a tail call replaced the failing frame (a forward method raising), the failing message comes from originalCall / caughtMessage.

Cost: raising an exception is about 7-10% slower (roughly 3µs on ~30µs).

Known limit: a tail call reuses its caller's frame, so the caller of a method's last call has no entry.

Tests: new BacktraceTest.io (10 cases) and a Node test for the browser build. 274 Io tests pass on the core and component builds, the C suite, 30 Node tests, and 83/83 in-page tests.

Also: Guide section on stack traces, an Unreleased release-notes entry, Plan.md updated, site regenerated.

🤖 Generated with Claude Code

https://claude.ai/code/session_011WETVfgtbJ5chDp7AeZUe9

Uncaught errors printed "nothing on stack": the backtrace was built from
Call objects on the retain stack, which the stackless evaluator no longer
leaves there, and the frames are unwound before anything prints.

An exception now records its trace from the frame chain at the moment it
is raised (IoState_error_ and Coroutine rawSignalException): the raising
frame, then each frame waiting on a method or block it called, capped at
64 entries. Exception stackTraceLines formats it; Coroutine backTraceString
prints it. pass keeps the original trace. The failing message is added
from originalCall or caughtMessage when a tail call replaced its frame.

Raising costs about 7-10% more (roughly 3 microseconds).

Known limit: a tail call reuses its caller's frame, so the caller of a
method's last call has no entry.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011WETVfgtbJ5chDp7AeZUe9
@stevedekorte
stevedekorte merged commit e2c4c8a into master Nov 17, 2026
1 check passed
@stevedekorte
stevedekorte deleted the backtraces branch November 17, 2026 19:34
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.

1 participant