Skip to content

require() to accept custom errors instead of a message #15214

@CedarMist

Description

@CedarMist

The require(cond, message); syntax is nice and lets you think clearly about the restrictions you're enforcing because the condition is a positive (it's easier to think 'when this condition is true, do X', versus 'when this condition isn't true, do X').

require( n <= MAX_NFTS_PER_COLLECTION, "ec.TOOMANY" );

And custom errors are nice, because it lets you include additional contextual information along-side an error. However to raise custom errors you must invert the condition which can be slightly more annoying to think about.

if(n > MAX_NFTS_PER_COLLECTION) revert ExtendedTooMany(collectionId)

I suggest that the second parameter of require be adjusted to either pass a message string or an expression which returns an Error type:

require( n <= MAX_NFTS_PER_COLLECTION, ExtendedTooMany(collectionId) );

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions