zink icon indicating copy to clipboard operation
zink copied to clipboard

Gather the declaration of errors

Open clearloop opened this issue 1 year ago • 6 comments

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 https://github.com/zink-lang/zink/pull/281#pullrequestreview-2475201842

clearloop avatar Oct 30 '24 20:10 clearloop

hey @clearloop, assign me

g4titanx avatar Dec 03 '24 21:12 g4titanx

@clearloop is there an existing error handling infrastructure?

g4titanx avatar Dec 11 '24 08:12 g4titanx

@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 avatar Dec 11 '24 10:12 clearloop

great! thanks

g4titanx avatar Dec 12 '24 11:12 g4titanx

great! thanks

see my implementation in https://github.com/zink-lang/zink/pull/298/commits/a8a3eeca309de405e427ddfb1284ed2f62709e7d, it's actually the same for this issue ^ ^

clearloop avatar Dec 12 '24 18:12 clearloop

@clearloop assign me

malik672 avatar Dec 13 '24 18:12 malik672