Skip to content

feat!: add support for abi errors #1651

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 17 commits into from
May 13, 2025
Merged

feat!: add support for abi errors #1651

merged 17 commits into from
May 13, 2025

Conversation

hal3e
Copy link
Contributor

@hal3e hal3e commented Apr 23, 2025

closes: #1648

Release notes

In this release, we:

  • Added support for the new abi errors. See the RFC for more information.

Summary

  • Updated fuel-abi-types to v0.12.0. This version supports the new error information.
  • Refactored the sdk code to update the error description when a panic is encountered.
  • Updated the forc commands in the CI to use --experimental error_type

For example, this sway code

struct B {
    id: u64,
    val: u64,
}

#[error_type]
enum MyError {
    #[error(m = "some error A")]
    A: (),
    #[error(m = "some complex error B")]
    B: B,
}

//-----> some contract or script code

panic MyError::B(B {
    id: 42,
    val: 36,
});

will produce this error message:

"panicked at: `contract_logs` - `src/main.sw:200:9` with message `some complex error B: B { id: 42, val: 36 }`"

Breaking Changes

  • LogFormatter constructors renamed

    // old
    let fmt = LogFormatter::new::<MyLog>();
    
    // new
    // for ordinary logs
    let fmt = LogFormatter::new_log::<MyLog>();
    // for enums tagged with #[error_type]
    let fmt_err = LogFormatter::new_error::<MyError>();
  • LogDecoder::new now needs the error-code map from the ABI

    // old
    let decoder = LogDecoder::new(formatters);
    
    // new
    use std::collections::HashMap;
    use fuels::core::codec::{ErrorDetails, LogDecoder};
    
    let formatters = /* HashMap<LogId, LogFormatter> */;
    let error_codes: HashMap<u64, ErrorDetails> = /* generated by Abigen or hand-built */;
    
    let decoder = LogDecoder::new(formatters, error_codes);

Checklist

  • All changes are covered by tests (or not applicable)
  • All changes are documented (or not applicable)
  • I reviewed the entire PR myself (preferably, on GH UI)
  • I described all Breaking Changes (or there's none)

@hal3e hal3e self-assigned this Apr 23, 2025
@hal3e hal3e force-pushed the feat/abi-errors branch from d693421 to 048d1c8 Compare May 2, 2025 10:18
@hal3e hal3e marked this pull request as ready for review May 7, 2025 22:27
@hal3e hal3e requested a review from a team as a code owner May 7, 2025 22:27
@hal3e hal3e requested a review from segfault-magnet May 8, 2025 08:51
segfault-magnet
segfault-magnet previously approved these changes May 9, 2025
Copy link

@netrome netrome left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some questions about the forc and sway patches that I'd like to get clarified before approving. Otherwise looks good to me.

@hal3e hal3e requested a review from segfault-magnet May 12, 2025 12:46
Copy link

@netrome netrome left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification and update 🙏

ironcev added a commit to FuelLabs/sway that referenced this pull request May 12, 2025
## Description

This PR removes the double compilation of contract methods in the IR, in
the case of new encoding.

The contract methods were first compiled as a part of the compilation of
the `__entry` function, and afterwards, again separately. The contract
methods compiled in the second compilation pass were later on removed as
not reachable.

The issue was brought to the surface in a test written by @hal3e in
[fuel-rs PR that integrates ABI
errors](FuelLabs/fuels-rs#1651). In that
particular test, because of the double compilation, a `panic` expression
in a contract method got compiled twice and produced two same entries in
the ABI JSON.

Removing the double compilation resulted in a small reduction of
bytecode size and gas usage. In some tests bytecode size got reduced for
~50 bytes and the gas usage for ~30 gas units.

Additionally, the PR adjusts the printing of IR global variables, to be
the same as printing of configurables and locals, without the spaces
between individual entries.

## Checklist

- [ ] I have linked to any relevant issues.
- [x] 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.
- [x] 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).
- [x] I have requested a review from the relevant team or maintainers.
@hal3e hal3e merged commit 69ce346 into master May 13, 2025
45 checks passed
@hal3e hal3e deleted the feat/abi-errors branch May 13, 2025 10:58
@xgreenx xgreenx mentioned this pull request May 13, 2025
4 tasks
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.

Support for new abi errors
3 participants