Skip to content
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

Closed

Conversation

chungquantin
Copy link
Collaborator

@chungquantin chungquantin commented Oct 4, 2024

Moving the conversion code DispatchError -> V0Error for pop_primitives::Error in devnet/versioning.rs to pop_primitives to handle DispatchError -> 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:

Note: Due to the empty feature runtime in pop-primitives, zepter and taplo conflicts

Copy link
Collaborator

@peterwht peterwht left a 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 = [ ]
Copy link
Collaborator

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How?

Copy link
Collaborator

@Daanvdplas Daanvdplas left a 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.

primitives/src/lib.rs Outdated Show resolved Hide resolved
@@ -7,6 +7,8 @@ use codec::{Decode, Encode};
use enum_iterator::Sequence;
#[cfg(feature = "std")]
use scale_info::TypeInfo;
#[cfg(feature = "runtime")]
Copy link
Collaborator

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.

Suggested change
#[cfg(feature = "runtime")]
#[cfg(all(feature = "runtime", feature = "std"))]

Copy link
Collaborator Author

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")]
Copy link
Collaborator

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.

Copy link
Collaborator Author

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 {
Copy link
Collaborator

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:

Suggested change
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 .

runtime/devnet/src/config/api/versioning.rs Outdated Show resolved Hide resolved
@evilrobot-01
Copy link
Collaborator

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?

@chungquantin
Copy link
Collaborator Author

With the refactor in r0gue-io/pop-drink#14 this PR is no longer needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants