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.
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 anError::Transaction(returned from a '.simulate().await' or '.call().await') where reason isReason::Failure. I think it may be as simple as generating something like this viaabigen!(pseudo-code):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.