Commit 936e752
authored
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
- #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]>1 parent 0682209 commit 936e752
File tree
6 files changed
+535
-58
lines changed- docs/book/src/testing
- forc-plugins/forc-client/src/op/call
- trace
- forc-test/src
- forc-util/src
6 files changed
+535
-58
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
199 | 199 | | |
200 | 200 | | |
201 | 201 | | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
202 | 233 | | |
203 | 234 | | |
204 | 235 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
284 | 284 | | |
285 | 285 | | |
286 | 286 | | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
| 287 | + | |
308 | 288 | | |
309 | 289 | | |
| 290 | + | |
| 291 | + | |
310 | 292 | | |
311 | 293 | | |
312 | 294 | | |
| |||
315 | 297 | | |
316 | 298 | | |
317 | 299 | | |
318 | | - | |
| 300 | + | |
319 | 301 | | |
320 | 302 | | |
321 | 303 | | |
322 | 304 | | |
323 | 305 | | |
324 | 306 | | |
325 | 307 | | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | 308 | | |
330 | 309 | | |
331 | 310 | | |
| |||
346 | 325 | | |
347 | 326 | | |
348 | 327 | | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
349 | 358 | | |
350 | 359 | | |
351 | 360 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
| 13 | + | |
15 | 14 | | |
16 | 15 | | |
17 | 16 | | |
| |||
286 | 285 | | |
287 | 286 | | |
288 | 287 | | |
289 | | - | |
| 288 | + | |
290 | 289 | | |
291 | 290 | | |
292 | 291 | | |
| |||
0 commit comments