Parsing custom contract errors

I am hitting a contract that follows an error emitting pattern like:

log(CustomError::ErrorOne)
revert(0)

where CustomError is defined as:

pub enum CustomError {
ErrorOne: (),
ErrorTwo: (),

}

In rust code, when calling a function (either by call() or simulate()) I sometimes see these reversions, as I would expect. In these cases, I am just given an Err() result with some log data. Is there a trivial way to detect and parse out my custom errors from this? Of course, I may not actually see my custom error and it may be an unrelated reversion/error, so ideally it’s easy to distinguish that too.

1 Like

I have updated my contract to use the new #[error_type] #[error] and panic, but my question largely remains the same.

1 Like

Turns out decoding logs from a reversion with decode_logs_with_type::<AbigenErrorType>(&receipts) does the trick!

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.