Skip to content

Gather the declaration of errors #256

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

Open
clearloop opened this issue Oct 30, 2024 · 6 comments
Open

Gather the declaration of errors #256

clearloop opened this issue Oct 30, 2024 · 6 comments
Assignees
Labels
bounty-$150 Payable large onboarding issues

Comments

@clearloop
Copy link
Member

clearloop commented Oct 30, 2024

Describe the feature

Error has not been implemented yet, ABIs are also required but considered in a separated PR

Solution

#[derive(Errors)]
enum Error {
  ERC20InvalidSender { sender: Address }
}

This solution could be similar as the events, see #281 (review)

@clearloop clearloop added bounty-$50 Payable small onboarding issues bounty-$100 Payable medium onboarding issues and removed bounty-$50 Payable small onboarding issues labels Nov 26, 2024
@g4titanx
Copy link
Member

g4titanx commented Dec 3, 2024

hey @clearloop, assign me

@g4titanx
Copy link
Member

@clearloop is there an existing error handling infrastructure?

@clearloop
Copy link
Member Author

clearloop commented Dec 11, 2024

@clearloop is there an existing error handling infrastructure?

we currently just have revert!, if I'm not mistaken, solidity errors are using revert internally as well, you can check the proc-macro implementation by @malik672 in #298, the logic is the same

the main difference are:

  1. logs need to call log1, log2, log3, log4, and we need to use revert!, revert1!...revert4! (maximum 4 parameters)
  2. for errors, we need to append the variables to the memory as well, then we can revert (name + parameters) together
#[derive(Error)]
pub enum Error {
  Error0,
  Error1(Bytes32),
  Error2(Bytes32, Bytes32),
  Error3(Bytes32, Bytes32, Bytes32),
  Error4(Bytes32, Bytes32, Bytes32, Bytes32)
}

// which generates

impl Error {
  fn error0() {
    zink::revert!("Error");
  }

  fn error1(param: Bytes32) {
    zink::revert!("Error", param)
  }

  // ...
}

for the revert macro, see revert!, and for the example, feel free to ask anything in the telegram channel!

@clearloop clearloop added bounty-$150 Payable large onboarding issues and removed bounty-$100 Payable medium onboarding issues labels Dec 11, 2024
@g4titanx
Copy link
Member

great! thanks

@clearloop
Copy link
Member Author

great! thanks

see my implementation in a8a3eec, it's actually the same for this issue ^ ^

@malik672
Copy link
Contributor

@clearloop assign me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bounty-$150 Payable large onboarding issues
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

3 participants