-
Notifications
You must be signed in to change notification settings - Fork 791
Expose contract revert errors in the ContractError struct #2172
Conversation
} | ||
|
||
/// Convert a Middleware Error to a `ContractError` | ||
pub fn from_middleware_error(e: M::Error) -> Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't make From<M::Error>
because it potentially conflicts with blanket From<T> for T
in cases where M::Error
and ContractError<M>
are the same type
yes this is weird
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this would be fixed with specialization, but alas
ethers-contract/src/call.rs
Outdated
#[error("{0}")] | ||
MiddlewareError(M::Error), | ||
#[error("{e}")] | ||
MiddlewareError { e: M::Error }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deliberately broken 3rd party direct instantiation, so that users must use the from_middleware_error
method
similar for provider error. broke it to force From
usage
/// Inspired by ethers-js logic: | ||
/// https://github.com/ethers-io/ethers.js/blob/9f990c57f0486728902d4b8e049536f2bb3487ee/packages/providers/src.ts/json-rpc-provider.ts#L25-L53 | ||
pub fn as_revert_data(&self) -> Option<Bytes> { | ||
self.is_revert().then(|| self.data.as_ref().and_then(spelunk_revert)).flatten() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL about bool::then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
feature 👍, breaking change good w/ me
looks like linter error is related to #2171 |
3a8a8dc
to
3153ef5
Compare
1e870e1
to
35cb9c9
Compare
cc @DaniPopes this touches your recent work 😅 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@prestwich That's fine since you're integrating it with the general Contract error, my PR was mostly about having a better API for the multicall call methods
Motivation
Users don't have access to revert data. That sucks. I'm fixing it.
Solution
TODO:
PR Checklist