Skip to content

Promote custom errors to proper types. #15388

Open
@ekpyron

Description

@ekpyron

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    high effortA lot to implement but still doable by a single person. The task is large or difficult.medium impactDefault level of impactselected for developmentIt's on our short-term development

    Type

    No type

    Projects

    Status

    Consider to Promote

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions