Skip to content

Conversation

@gnarvaja
Copy link
Owner

Support for custom errors in base contracts: ERC20, ERC721 and AccessControl

Support for custom errors in base contracts: ERC20, ERC721 and
AccessControl
Comment on lines 545 to 582
def _error(self, error_class, *args) -> RevertError:
if error_class == "ERC721InvalidOwner":
if self.use_custom_errors:
return RevertCustomError(
error_class, args[0] if args else "0x0000000000000000000000000000000000000000"
)
else:
return RevertError("ERC721: address zero is not a valid owner")
elif error_class == "ERC721NonexistentToken":
if self.use_custom_errors:
return RevertCustomError(error_class, args[0])
else:
return RevertError("ERC721: invalid token ID")
elif error_class == "ERC721IncorrectOwner":
if self.use_custom_errors:
return RevertCustomError(error_class, args[0], args[1], args[2])
else:
return RevertError("ERC721: transfer from incorrect owner")
elif error_class == "ERC721InvalidSender":
if self.use_custom_errors:
return RevertCustomError(
error_class, args[0] if args else "0x0000000000000000000000000000000000000000"
)
else:
return RevertError("ERC721: transfer from incorrect owner")
elif error_class == "ERC721InvalidReceiver":
if self.use_custom_errors:
return RevertCustomError(
error_class, args[0] if args else "0x0000000000000000000000000000000000000000"
)
else:
return RevertError("ERC721: transfer to the zero address")
elif error_class == "ERC721InsufficientApproval":
if self.use_custom_errors:
return RevertCustomError(error_class, args[0], args[1])
else:
return RevertError("ERC721: caller is not token owner nor approved")
return super()._error(error_class, *args)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Podría aplicar acá lo mismo que decía arriba, solo si la opción del mapping es viable.

Thanks @LucasCambon for the review, now with less code duplication.
@gnarvaja gnarvaja merged commit 6610f40 into main Sep 11, 2025
2 checks passed
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 this pull request may close these issues.

3 participants