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

Use custom error types #130

Closed
ItsNickBarry opened this issue Jul 29, 2022 · 9 comments · Fixed by #139
Closed

Use custom error types #130

ItsNickBarry opened this issue Jul 29, 2022 · 9 comments · Fixed by #139

Comments

@ItsNickBarry
Copy link
Member

ItsNickBarry commented Jul 29, 2022

Replace error strings with custom error types: https://blog.soliditylang.org/2021/04/21/custom-errors/

@wiasliaw
Copy link
Contributor

wiasliaw commented Sep 8, 2022

Hi, @ItsNickBarry,
I can help with the this issue.
It will be a large commits including replacement and testing. I think it should create a branch for this issue. After everything is done, then merge into the master.

@ItsNickBarry
Copy link
Member Author

Okay, that would be appreciated. There are two open-ended questions that will need to be answered:

  1. Can we apply a naming convention to error types? Should we include contract name in the error name? For example, the existing error "Ownable: sender must be owner" could be replaced with something like OwnableSenderMustBeOwner or OwnableUnauthorized, or simply Unauthorized.
  2. What arguments should be included in the custom errors? This will vary case-by-case. Use your judgment, and we'll review later.

@wiasliaw
Copy link
Contributor

wiasliaw commented Sep 8, 2022

  1. I think it is OK for both included contract name or not. If not included the name, it should be careful that different contracts might have the same reason string. For example, "ERC20: transfer to the zero address" and "ERC721: transfer to the zero address" in Openzeppelin's implementation. But I didn't find that in solidstate-solidity.

  2. From my opinion, it is rare that arguments are placed in reason string. For example, "Ownable: ${address} is not the owner". For most of cases, good naming of custom error is enough. Arguments are included if providing better readability.

Some of the cases below providing arguments will be better:

@ItsNickBarry
Copy link
Member Author

I agree. Let's not include contract name in the error names. Go ahead and make the changes on your branch, and PR when ready.

@wiasliaw
Copy link
Contributor

wiasliaw commented Sep 11, 2022

@ItsNickBarry

Addressing some issues here.

  1. after adding custom error, abstract contracts and libraries also generated abi in /abi. For example, ECDSA generated the abi but only error selectors. I don't think it is OK.

  2. About testing, waffle supports custom error. Here's the PR. However, it combines reason string and custom error and make confusing readability. I might propose hardhat-chai-matchers.

@ItsNickBarry
Copy link
Member Author

Right, I forgot that library ABIs would be generated separately. I suppose that means that the errors defined in libraries only appear in the library ABIs, and not in the contract ABIs? I've had the same issue with events in the past.

If so, that might make this change untenable until tools are available to easily include library ABIs in the relevant contracts.

@wiasliaw
Copy link
Contributor

I don't know if it is OK to generate abi that user don't need. If a contract is import a .sol, which will generate the same abi.

@ItsNickBarry
Copy link
Member Author

Maybe I misunderstood. I did a test, and it seems like errors defined in libraries are properly included in the ABIs of contracts that import them. In that case, I don't see any issues.

I don't know if it is OK to generate abi that user don't need. If a contract is import a .sol, which will generate the same abi.

It's okay if extra ABIs are generated.

@ItsNickBarry
Copy link
Member Author

@Lumyo has opened PR #139.

@ItsNickBarry ItsNickBarry linked a pull request Sep 29, 2022 that will close this issue
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 a pull request may close this issue.

2 participants