Skip to content
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

feat(sol!)!: generate unit/tuple structs for errors with 0/1 param #883

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

yash-atreya
Copy link
Member

@yash-atreya yash-atreya commented Feb 19, 2025

Motivation

Closes #878

Solution

  • Generate a unit struct for error with no params and tuple struct for error with exactly one param
sol! {
   error SomeError();
   error AnotherError(uint256); // unnamed param
   error YetAnotherError(uint256 a); // named param

}
// Generates
pub struct SomeError;

// Expanded as tuple struct if single unnamed param
// The idea is to remove accessing the inner filed as `another_err._0`.
pub struct AnotherError(pub U256); 

pub struct YetAnotherError { a: U256 }; // Expanded as a struct with named fieled, same as previous bindings.

// Previous
pub struct SomeError {};

pub struct AnotherError { _0: U256 };

pub struct YetAnotherError { a: U256 } 
  • Bindings for errors with 2 or more params are unchanged.

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@yash-atreya yash-atreya added breaking enhancement New feature or request labels Feb 19, 2025
Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

style nits/suggestions

ptal @DaniPopes

@yash-atreya yash-atreya requested a review from mattsse February 27, 2025 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] feat(sol!)!: improve custom error bindings
2 participants