-
Notifications
You must be signed in to change notification settings - Fork 255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve Dispatch Errors #878
Conversation
subxt/src/error/mod.rs
Outdated
Other(String), | ||
} | ||
|
||
impl From<&str> for 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.
I think this is better, &str
implies only static &str
which is not that flexible to use.
impl From<&str> for Error { | |
impl<T: AsRef<str>> From<T> for 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.
But impl From<T>
I think would conflict with all of the other From<InnerError>
impls we have on Error
:(
Let me double check that..
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.
Ok nar that didn't work; conflicting impls!
I also did a test and this code worked fine:
fn test() {
let s = String::from("hello");
let r = s.as_str();
let _e = Error::from(r);
}
So I think the From<&str>
impl does not require &'static str
:)
(now I look at it I am surprised that I didn't have to provide an explicit lifetime there)
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.
Ok, I did exactly the same for a while ago and rustc inferred it as 'static
maybe just me 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.
I put an explicit lifetime on this to make it clear, and because I'm surprised I didn't need one already!
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.
👍
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.
LGTM!
Dispatch errors are a bit pants; we only decode the Module variant, and then we cloned a bunch of details out of metadata into it. This PR makes the following changes:
DispatchError
in ourdry_run
result too, so we get the same level of detail there (for dispatch erros at least).ModuleError
API; don't pull/clone things from metadata; call that on-demand instead.DecodeAsType
to decodeDispatchErrors
based on shape, so we don't have to worry about indexes changing if variants are added.#[non_exhaustive]
to future proof a little against new variants being added (withDecodeAsType
, this at least gives us a path to add new variants and deprecate old ones without worrying about index stuff).