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

pallet assets: Fix errors #4118

Merged
merged 5 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions prdoc/pr_4118.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
title: "pallet assets: minor improvement on errors returned for some calls"

doc:
- audience: Runtime Dev
description: |
Some calls in pallet assets have better errors. No new error is introduced, only more sensible choice are made.
- audience: Runtime User
description: |
Some calls in pallet assets have better errors. No new error is introduced, only more sensible choice are made.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I feel information is not useful, but in theory it impacts both dev for maybe test to udpate and frontend.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in theory it is kind of a major breaking change :-(


crates:
- name: pallet-assets
bump: minor
2 changes: 1 addition & 1 deletion substrate/frame/assets/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pallet-assets"
version = "29.0.0"
version = "29.1.0"
authors.workspace = true
edition.workspace = true
license = "Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/assets/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
let d = Asset::<T, I>::get(&id).ok_or(Error::<T, I>::Unknown)?;
ensure!(
d.status == AssetStatus::Live || d.status == AssetStatus::Frozen,
Error::<T, I>::AssetNotLive
Error::<T, I>::IncorrectStatus
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we say AssetNotLiveOrFrozen? Not sure if IncorrectStatus is much helpful.

Copy link
Contributor

@liamaharon liamaharon Apr 15, 2024

Choose a reason for hiding this comment

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

I'm personally fine with IncorrectStatus. It's non-ambiguous since it's only used in one context, and allows for us to add new statuses in the future without needing to update the error.

Copy link
Contributor Author

@gui1117 gui1117 Apr 15, 2024

Choose a reason for hiding this comment

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

AssetNotLiveNorFrozen or AssetNotLiveOrFrozen ?
I will do.

Copy link
Contributor

Choose a reason for hiding this comment

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

allows for us to add new statuses in the future without needing to update the error.

Yeah, it helps us, but not sure someone using a UI would get any info with the IncorrectStatus error. Either ways, its fine but I would prefer the errors to be more meaningful for the users.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think Rust enum errors are supposed to be shown directly to end-users in UIs? I always understood them as more for developers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some UI might show the doc: /// The asset status is not the expected status.

Considering there is 3 status I think it is ok

);

let actual = Self::decrease_balance(id.clone(), target, amount, f, |actual, details| {
Expand Down
8 changes: 4 additions & 4 deletions substrate/frame/assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ pub mod pallet {
let d = Asset::<T, I>::get(&id).ok_or(Error::<T, I>::Unknown)?;
ensure!(
d.status == AssetStatus::Live || d.status == AssetStatus::Frozen,
Error::<T, I>::AssetNotLive
Error::<T, I>::IncorrectStatus
);
ensure!(origin == d.freezer, Error::<T, I>::NoPermission);
let who = T::Lookup::lookup(who)?;
Expand Down Expand Up @@ -1024,7 +1024,7 @@ pub mod pallet {
let details = Asset::<T, I>::get(&id).ok_or(Error::<T, I>::Unknown)?;
ensure!(
details.status == AssetStatus::Live || details.status == AssetStatus::Frozen,
Error::<T, I>::AssetNotLive
Error::<T, I>::IncorrectStatus
);
ensure!(origin == details.admin, Error::<T, I>::NoPermission);
let who = T::Lookup::lookup(who)?;
Expand Down Expand Up @@ -1113,7 +1113,7 @@ pub mod pallet {

Asset::<T, I>::try_mutate(id.clone(), |maybe_details| {
let details = maybe_details.as_mut().ok_or(Error::<T, I>::Unknown)?;
ensure!(details.status == AssetStatus::Live, Error::<T, I>::LiveAsset);
ensure!(details.status == AssetStatus::Live, Error::<T, I>::AssetNotLive);
ensure!(origin == details.owner, Error::<T, I>::NoPermission);
if details.owner == owner {
return Ok(())
Expand Down Expand Up @@ -1669,7 +1669,7 @@ pub mod pallet {
let d = Asset::<T, I>::get(&id).ok_or(Error::<T, I>::Unknown)?;
ensure!(
d.status == AssetStatus::Live || d.status == AssetStatus::Frozen,
Error::<T, I>::AssetNotLive
Error::<T, I>::IncorrectStatus
);
ensure!(origin == d.freezer, Error::<T, I>::NoPermission);
let who = T::Lookup::lookup(who)?;
Expand Down
Loading