Content pfp
Content
@
0 reply
0 recast
0 reaction

Mark Tyneway pfp
Mark Tyneway
@tynes
What are best practices for custom errors? - When should they include arguments? - Should there be many diff error types or more generic errors that accept arguments to differentiate error cases?
2 replies
2 recasts
10 reactions

William pfp
William
@wtracy
Always favor multiple error types over using an enumeration as an argument. Arguments are for free-form data that can't be known at compile time. Provide information useful to someone who can't see your contract's state or source code. Don't repeat transaction information they already have.
0 reply
0 recast
2 reactions

Jem pfp
Jem
@jem
As long as you have enough space in the contract, I'd go for more verbose/specialised errors, as it makes it easier for a third-party to diagnose the cause of the error. I've also started putting the errors (alongside other functions, state variable functions, etc) into an interface, to save devs having to import the implementation.
0 reply
0 recast
0 reaction

Bmatt Music pfp
Bmatt Music
@bmattmusic
Error handling is usually pretty specific to the purpose of the function and how it’s applied. In web2 error codes typically dictate what your error should do. Do you have a specific example you’re working through?
0 reply
0 recast
0 reaction