Skip to content

Conversation

yash-atreya
Copy link
Member

@yash-atreya yash-atreya commented Sep 4, 2025

Motivation

Closes #2328

Forge lacks backtraces, which are useful for pinpointing the line where the revert/error originated in the call stack. This is especially useful when there are multiple nested calls between different contracts, making traces hard to follow. Backtraces help you easily "goto" the line throwing the error.

Solution

  • Introduce backtrace support in forge test
  • Backtraces are enabled when verbosity >= 3 and printed if there is a revert
  • When verbosity >= 3, we collect the source maps, deployed bytecode, and source content.
  • In case a test fails, extract the backtraces using extract_backtraces; thebytecode.pc (program counter) is mapped to the instruction pointer and then source maps are used to pinpoint the source locations in the call stack.
  • Each call is stored as a BacktraceFrame containing the source location of the call along with the contract and function names.

Implementation can be tested using:

wip

TODOs

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@yash-atreya yash-atreya self-assigned this Sep 4, 2025
@yash-atreya yash-atreya added A-testing Area: testing Cmd-forge-test Command: forge test C-forge Command: forge labels Sep 4, 2025
@yash-atreya yash-atreya moved this to In Progress in Foundry Sep 4, 2025
@yash-atreya yash-atreya added the T-feature Type: feature label Sep 4, 2025
@grandizzy grandizzy added this to the v1.4.0 milestone Sep 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-testing Area: testing C-forge Command: forge Cmd-forge-test Command: forge test T-feature Type: feature
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

feat: extend (error) traces to include source code line number and filename
2 participants