Skip to content

fix(ir): preserve error stacktraces in catch expressions - #55

Merged
mremond merged 2 commits into
mainfrom
fm/task-f7c72c66
Nov 15, 2026
Merged

mremond merged 2 commits into
mainfrom
fm/task-f7c72c66

Conversation

@mremond

@mremond mremond commented Nov 15, 2026

Copy link
Copy Markdown
Member

Why

Error results from catch expressions should retain the diagnostic frames already available through try/catch.

What changed

  • Catch expressions return captured error stacktraces instead of an empty list.
  • Re-raised errors retain their supplied stacktrace, including an explicitly empty trace.
  • Normal results, throws and exits retain their existing result forms.

Before and after

Before: Error catch results contained 0 stacktrace frames, even when try/catch captured the failing function and its callers.

After: Ordinary caught errors retain 3 shared frames and their metadata, matching try/catch; explicitly empty supplied traces still contain 0 frames.

This changes returned Erlang terms, not a graphical view; compiled-program transcripts demonstrate the result.

Checked

Live validation: Demonstrated for this version. 3 of 3 scenarios driven live in the product.

Scenario Result Evidence
Catch error, badmatch and arithmetic failures through shared non-tail calls. ✅ Passed live Native default, native single and BEAM each passed ten consecutive frame and metadata comparisons.
Catch an error after an observed suspension and message release. ✅ Passed live Both catch forms retain matching available frames after actual resumption on native and BEAM.
Preserve supplied traces and unchanged catch result forms. ✅ Passed live Real full, shortened and empty traces, nested catches, later errors and normal/throw/exit controls passed in every execution.
  • Rust workspace tests: 2,202 passed with no failures; one existing test remained ignored.
  • Complete native suite: 506 passed, no failures and two external-module tests skipped.
  • Release builds and strict lint: Runtime-first compiler build and workspace clippy passed.
  • Allocator and crash-report probes: Default/override allocator options and innermost-first uncaught stacktrace output passed.
  • Cross-target object probes: Produced the expected x86_64 macOS and ARM64 Linux object formats.
  • Independent code review: Passed after replacing immediate-timeout coverage with observed message-gated suspension; the later update preserved the reviewed implementation.
How it was checked

cargo build --release --locked -p nera-runtime; cargo build --release --locked -p nera

cargo clippy --workspace --all-targets --locked -- -D warnings

cargo test --workspace --locked --no-fail-fast

./target/release/nera test -j 1 --timeout 30

python3 scripts/test-allocator-config.py; python3 scripts/test-stacktrace-order.py

bash scripts/test-cross.sh ./target/release/nera x86_64-apple-darwin; bash scripts/test-cross.sh ./target/release/nera aarch64-unknown-linux-gnu

The new Erlang fixture ran ten times per native scheduler mode and on BEAM, with both its completion marker and an asserted ok return.

An intermediate suspension assertion failed during development; the corrected fixture and final complete suite pass.

Risk

Risk: low in every dimension.

Full risk assessment
Dimension Level Why
Blast radius low Only unary catch error-result desugaring changes.
Behavior low Corrects missing diagnostic frames without changing other result forms.
Undo low Reverting the change requires no data migration.
Evidence low Compiled native and BEAM programs demonstrate all recorded scenarios.
Sensitivity low No sign-ins, keys, payments or saved data are changed.
Novelty low Uses the existing try/catch stacktrace binding path.
Dependencies low No dependency changes.
Not done

Native try/catch's existing loss of caller frames across suspension is outside this fix; catch retains the same available trace.

Two native tests require external example modules and remain skipped.

Cross-target probes inspect object formats; Windows execution was not validated.

Pipeline

Updates from git push no-mistakes

Infinitary checked this version: an independent review that also judged the documents, and live validation the review accepted.

@github-actions github-actions Bot added this to the 0.1.1 milestone Nov 15, 2026
@mremond
mremond merged commit 71784d3 into main Nov 15, 2026
22 checks passed
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