-
Notifications
You must be signed in to change notification settings - Fork 7
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
refactor: primitive error conversion #327
refactor: primitive error conversion #327
Conversation
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.
Nice! Pretty straightforward. Would like to see the CI pass before approving
|
||
[dev-dependencies] | ||
enum-iterator = "2.1.0" | ||
|
||
[features] | ||
default = [ "std" ] | ||
std = [ "codec/std", "scale-info/std" ] | ||
runtime = [ ] |
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.
would recommend putting some placeholder in here to make zepter and taplo happy.
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.
How?
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.
Still some rough edges tmo.
@@ -7,6 +7,8 @@ use codec::{Decode, Encode}; | |||
use enum_iterator::Sequence; | |||
#[cfg(feature = "std")] | |||
use scale_info::TypeInfo; | |||
#[cfg(feature = "runtime")] |
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.
Drink importing this crate with runtime
feature feels odd.
#[cfg(feature = "runtime")] | |
#[cfg(all(feature = "runtime", feature = "std"))] |
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.
Why do we need std
? These imports are only required for the conversion, and the conversion is only enabled for runtime
feature.
|
||
// Compare all the different `DispatchError` variants with the expected `Error`. | ||
#[test] | ||
#[cfg(feature = "runtime")] |
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.
This should not be required if the "std" feature is added.
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.
Without runtime
feature enabled, the conversion Error::from
does not work because From<DispatchError>
is only enabled when there is runtime
.
@@ -103,17 +103,9 @@ struct V0Error(pop_primitives::v0::Error); | |||
impl From<DispatchError> for V0Error { | |||
fn from(error: DispatchError) -> 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.
Preferably this should just be:
fn from(error: DispatchError) -> Self { | |
fn from(error: DispatchError) -> Self { | |
Self(error.into()) | |
} |
Makes me wonder whether to remove that whole DecodingFailed
variant as the developer should never receive this error anyway @evilrobot-01 .
Forgive me if I am missing something, but if drink is implying/requiring a dependency on a specific runtime, then why can't we just reuse the error conversion defined within the runtime rather than moving into primitives? |
With the refactor in r0gue-io/pop-drink#14 this PR is no longer needed. |
Moving the conversion code
DispatchError -> V0Error
forpop_primitives::Error
indevnet/versioning.rs
topop_primitives
to handleDispatchError -> pop_primitives::Error
.We need this refactor for for the pop-api refactor in example contract to work. For more context, please take a look at:
PSP22Error
conversion & assertion #324.Note: Due to the empty feature
runtime
inpop-primitives
, zepter and taplo conflicts