sway/forc-util
zees-dev 936e752176
feat: forc-call abi backtracing (#7502)
## 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
- https://github.com/FuelLabs/sway/pull/7224
- https://github.com/FuelLabs/sway/pull/7277
- https://github.com/FuelLabs/fuel-abi-types/pull/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
957d411acb. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

---------

Co-authored-by: z <zees-dev@users.noreply.github.com>
2025-11-26 13:01:36 +04:00
..
src feat: forc-call abi backtracing (#7502) 2025-11-26 13:01:36 +04:00
tests/fixtures/bytecode feat: add function for generating bytecode identifier (#6674) 2024-11-19 08:49:41 -08:00
Cargo.toml chore: bumpt rust version to 1.90 (#7427) 2025-10-02 22:28:51 +13:00