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

Promote custom errors to proper types. #15388

Open
ekpyron opened this issue Sep 2, 2024 · 0 comments
Open

Promote custom errors to proper types. #15388

ekpyron opened this issue Sep 2, 2024 · 0 comments
Labels
high effort A lot to implement but still doable by a single person. The task is large or difficult. medium impact Default level of impact selected for development It's on our short-term development
Milestone

Comments

@ekpyron
Copy link
Member

ekpyron commented Sep 2, 2024

We already introduced the ability to use custom errors as second argument for require.
Ultimately, we can treat custom errors as regular types that can be stored in local variables and passed to functions like normal arguments. This could be done either by introducing a separate type for each custom error or by introducing a generic type error - in either case the value would be encoded as a bytes memory containing the abi-encoding of the error. Conceptually, that's also what already happens for "require with custom error".

Moving further in this direction will take some work, since it involves thinking about all explicit and implicit conversion behaviour of the new custom error type (as well as the question whether it should be one or several types still needs to be settled).

However, we can already continue in this direction by allowing an explicit conversion from calls to error constructors to bytes memory.

So as a next step we can allow:

error CustomError(uint);
function f() public {
  bytes memory errorEncoding = bytes(CustomError(42));
}

this would solve the use case of #14974 (comment), resp. would supersede #14287

The specification for this first step would be:
Calls to error constructors can still only occur in revert statements, as second argument to require, and (with this change) also as arguments to a type conversion call to bytes. The resulting type would be bytes memory.

@ekpyron ekpyron added selected for development It's on our short-term development high effort A lot to implement but still doable by a single person. The task is large or difficult. medium impact Default level of impact labels Sep 2, 2024
@ekpyron ekpyron added this to the 0.8.28 milestone Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
high effort A lot to implement but still doable by a single person. The task is large or difficult. medium impact Default level of impact selected for development It's on our short-term development
Projects
Development

No branches or pull requests

1 participant