-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Add #[trace] attribute
#7277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add #[trace] attribute
#7277
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CodSpeed Performance ReportMerging #7277 will not alter performanceComparing Summary
|
zees-dev
reviewed
Jul 11, 2025
zees-dev
approved these changes
Jul 11, 2025
Contributor
zees-dev
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
tritao
approved these changes
Jul 11, 2025
8 tasks
zees-dev
added a commit
that referenced
this pull request
Nov 26, 2025
## Description This PR introduces panic/error traces to the forc call trace output. This functionality is built on top of the existing abi-backtracing introduced in the following: - https://github.com/FuelLabs/sway-rfcs/blob/master/rfcs/0016-abi-backtracing.md - #7224 - #7277 - FuelLabs/fuel-abi-types#36 - https://github.com/FuelLabs/fuel-abi-types/pull/40/files Supplying verbosity level greater than 1 (i.e. `-vv` or `-v=2`) will display the panic/error traces when using `forc-call`. If the called function panics, the panic message and the full backtrace will be displayed in the trace output. ## Example <details> <summary>Example contract code</summary> ```sway contract; abi AbiErrorDemo { #[storage(write)] fn write_non_zero(value: u64); #[storage(read)] fn read_value() -> u64; } storage { value: u64 = 0, } #[error_type] pub enum PanicError { #[error(m = "The provided value must be greater than zero.")] ZeroValue: (), } impl AbiErrorDemo for Contract { #[storage(write)] fn write_non_zero(value: u64) { set_non_zero_value(value); } #[storage(read)] fn read_value() -> u64 { storage.value.read() } } #[trace(always)] #[storage(write)] fn set_non_zero_value(value: u64) { ensure_non_zero(value); storage.value.write(value); } #[trace(always)] fn ensure_non_zero(value: u64) { ensure_non_zero_impl(value); } #[trace(always)] fn ensure_non_zero_impl(value: u64) { if value == 0 { panic PanicError::ZeroValue; } } ``` </details> Example Call: ```sh cargo run -p forc-client --bin forc-call -- \ --abi out/debug/abi_errors-abi.json \ babdc125da45eac42309e60d3aea63a53843f5ff2438d1a88bf8c788e8348c58 \ write_non_zero "0" -vv ``` Example Output: <img width="857" height="340" alt="Screenshot 2025-11-24 at 8 36 00 PM" src="https://github.com/user-attachments/assets/9a14053e-9318-4543-a01a-0d794e30dff2" /> ## Checklist - [ ] I have linked to any relevant issues. - [ ] I have commented my code, particularly in hard-to-understand areas. - [ ] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [ ] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [ ] I have added tests that prove my fix is effective or that my feature works. - [ ] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [ ] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [ ] I have requested a review from the relevant team or maintainers. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Adds ABI-aware revert decoding to forc-call, displaying panic messages, values, and backtraces in verbose traces and surfacing revert errors early. > > - **forc-client (call/trace)**: > - Add ABI-aware revert decoding (`RevertInfoSummary`) and integrate into `TraceEvent::Revert`; render panic message, value, location, and backtrace in `display_transaction_trace`. > - New helpers: `decode_revert_info` and `first_revert_info` to extract revert details from receipts and trace. > - `call_function`: generate receipts once, include in interpreter, display detailed info on verbosity, and return an error early when a revert is detected; parse outputs after. > - Minor: reference `trace::display_transaction_trace` directly; extend tests to cover revert detail rendering. > - **forc-util**: > - Add `revert_info_from_receipts` to build `RevertInfo` (revert code, panic metadata) from receipts using optional ABI. > - **forc-test**: > - Replace `revert_code()` with `revert_info()` using new utility; filter by actual revert code; simplify API. > - **Docs**: > - Add "Seeing revert information and backtraces" section with example usage/output for `forc call -vv`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 957d411. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: z <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
compiler: frontend
Everything to do with type checking, control flow analysis, and everything between parsing and IRgen
compiler
General compiler. Should eventually become more specific as the issue is triaged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR adds the
#[trace]attribute as described in the ABI Backtracing RFC.This is the first step in implementing #7276.
Docs for
#[trace]attribute will be added in a separate PR that will document the whole backtracking feature.A check if an annotated function can actually panic will be added in a follow up PR that will implement the backtracing in the IR generation.
Checklist
Breaking*orNew Featurelabels where relevant.