This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This pr implements support for returning errors of different pallets in a pallet. These errors need to be declared with `decl_error!`. The pr changes the following: - Each dispatchable function now returns a `DispatchResult` which is an alias for `Result<(), DispatchError>`. - `DispatchError` is an enum that has 4 variants: - `Other`: For storing string error messages - `CannotLookup`: Variant that is returned when something returns a `sp_runtime::LookupError` - `BadOrigin`: Variant that is returned for any kind of bad origin - `Module`: The error of a specific module. Contains the `index`, `error` and the `message`. The index is the index of the module in `construct_runtime!`. `error` is the index of the error in the error enum declared by `decl_error!`. `message` is the message to the error variant (this will not be encoded). - `construct_runtime!` now creates a new struct `ModuleToIndex`. This struct implements the trait `ModuleToIndex`. - `frame_system::Trait` has a new associated type: `ModuleToIndex` that expects the `ModuleToIndex` generated by `construct_runtime!`. - All error strings returned in any module are being converted now to `DispatchError`. - `BadOrigin` is the default error returned by any type that implements `EnsureOrigin`.
stanislav-tkach
approved these changes
Dec 18, 2019
shawntabrizi
approved these changes
Dec 18, 2019
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.
The API looks good :)
Thank you Basti!
niklasad1
reviewed
Dec 19, 2019
if reasons.intersects(WithdrawReason::Reserve | WithdrawReason::Transfer) | ||
&& Self::vesting_balance(who) > new_balance | ||
{ | ||
return Err("vesting balance too high to send value"); | ||
Err("vesting balance too high to send value")? |
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.
personally I prefer return Err("fooo".into())
because it is more explicit than Err("foo")?
but it's fine either way.
This was referenced Dec 23, 2019
sorpaas
pushed a commit
that referenced
this pull request
Nov 20, 2020
* Make `decl_error!` errors usable This pr implements support for returning errors of different pallets in a pallet. These errors need to be declared with `decl_error!`. The pr changes the following: - Each dispatchable function now returns a `DispatchResult` which is an alias for `Result<(), DispatchError>`. - `DispatchError` is an enum that has 4 variants: - `Other`: For storing string error messages - `CannotLookup`: Variant that is returned when something returns a `sp_runtime::LookupError` - `BadOrigin`: Variant that is returned for any kind of bad origin - `Module`: The error of a specific module. Contains the `index`, `error` and the `message`. The index is the index of the module in `construct_runtime!`. `error` is the index of the error in the error enum declared by `decl_error!`. `message` is the message to the error variant (this will not be encoded). - `construct_runtime!` now creates a new struct `ModuleToIndex`. This struct implements the trait `ModuleToIndex`. - `frame_system::Trait` has a new associated type: `ModuleToIndex` that expects the `ModuleToIndex` generated by `construct_runtime!`. - All error strings returned in any module are being converted now to `DispatchError`. - `BadOrigin` is the default error returned by any type that implements `EnsureOrigin`. * Fix frame system benchmarks
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pr implements support for returning errors of different pallets in
a pallet. These errors need to be declared with
decl_error!
.The pr changes the following:
DispatchResult
which is analias for
Result<(), DispatchError>
.DispatchError
is an enum that has 4 variants:Other
: For storing string error messagesCannotLookup
: Variant that is returned when something returns asp_runtime::LookupError
BadOrigin
: Variant that is returned for any kind of bad originModule
: The error of a specific module. Contains theindex
,error
and themessage
. The index is the index of the module inconstruct_runtime!
.error
is the index of the error in the errorenum declared by
decl_error!
.message
is the message to the errorvariant (this will not be encoded).
construct_runtime!
now creates a new structModuleToIndex
. Thisstruct implements the trait
ModuleToIndex
.frame_system::Trait
has a new associated type:ModuleToIndex
thatexpects the
ModuleToIndex
generated byconstruct_runtime!
.DispatchError
.BadOrigin
is the default error returned by any type that implementsEnsureOrigin
.Fixes: #4409 #4040
@jacogr this changes the encoding of the
DispatchError
. Do you want to have a bump of the metadata to detect this?