[−][src]Macro frame_support::decl_error
Declare an error type for a runtime module.
decl_error!
supports only variants that do not hold any data. The dispatchable
functions return DispatchResult
. The error type
implements From<ErrorType> for DispatchResult
to make the error type usable as error
in the dispatchable functions.
It is required that the error type is registered in decl_module!
to make the error
exported in the metadata.
Usage
decl_error! { /// Errors that can occur in my module. pub enum MyError for Module<T: Trait> { /// Hey this is an error message that indicates bla. MyCoolErrorMessage, /// You are just not cool enough for my module! YouAreNotCoolEnough, } } // You need to register the error type in `decl_module!` as well to make the error // exported in the metadata. decl_module! { pub struct Module<T: Trait> for enum Call where origin: T::Origin { type Error = MyError<T>; #[weight = 0] fn do_something(origin) -> frame_support::dispatch::DispatchResult { Err(MyError::<T>::YouAreNotCoolEnough.into()) } } }
For instantiable modules you also need to give the instance generic type and bound to the error declaration.