Skip to content

Add a way to try to convert a transaction error into contract errors if present #1680

@HenryMBaldwin

Description

@HenryMBaldwin

The abigen! macro seems to generate enums with some special sauce for displaying when they're decorated with #[error_type] and #[error]. It seems unintuitive that theres no trivial way to attempt to convert/ extract one of the custom error enums from an Error::Transaction (returned from a '.simulate().await' or '.call().await') where reason is Reason::Failure. I think it may be as simple as generating something like this via abigen! (pseudo-code):

impl TryFrom<u64> for MyErrorEnum {
    fn try_from(revert_id: u64) -> Result<MyErrorEnum> {
        match revert_id {
            <revert-id-from-abi-1> => Ok(MyErrorEnum::ErrorOne),
            <revert-id-from-abi-2> => Ok(MyErrorEnum::ErrorTwo),
            ...,
            _ => return Err(),
}

Otherwise, it seems like the best way to do this is pattern matching on hardcoded values from the contract/abi, which is less robust to abi changes in future development.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions