From 467e01b991917aa5c9c2c5a0c2816b620a2b024f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Wed, 11 Dec 2019 20:48:55 +0100 Subject: [PATCH] `decl_error!` document that the error needs to be registered (#4366) --- substrate/frame/support/src/error.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/substrate/frame/support/src/error.rs b/substrate/frame/support/src/error.rs index 937be730f9..d256f0d58b 100644 --- a/substrate/frame/support/src/error.rs +++ b/substrate/frame/support/src/error.rs @@ -28,10 +28,12 @@ pub use frame_metadata::{ModuleErrorMetadata, ErrorMetadata, DecodeDifferent}; /// error type implements `From<&'static str>` and `From` to make them usable with the /// try operator. /// +/// `decl_error!` supports only variants that do not hold any data. +/// /// # Usage /// /// ``` -/// # use frame_support::decl_error; +/// # use frame_support::{decl_error, decl_module}; /// decl_error! { /// /// Errors that can occur in my module. /// pub enum MyError { @@ -41,9 +43,23 @@ pub use frame_metadata::{ModuleErrorMetadata, ErrorMetadata, DecodeDifferent}; /// YouAreNotCoolEnough, /// } /// } -/// ``` /// -/// `decl_error!` supports only variants that do not hold any data. +/// # use frame_system::{self as system, Trait, ensure_signed}; +/// +/// // You need to register the error type in `decl_module!` as well. +/// +/// decl_module! { +/// pub struct Module for enum Call where origin: T::Origin { +/// type Error = MyError; +/// +/// fn do_something(origin) -> Result<(), MyError> { +/// Err(MyError::YouAreNotCoolEnough) +/// } +/// } +/// } +/// +/// # fn main() {} +/// ``` #[macro_export] macro_rules! decl_error { (