diff --git a/src/events.rs b/src/events.rs index 880410fc61..b38d022d04 100644 --- a/src/events.rs +++ b/src/events.rs @@ -23,6 +23,7 @@ use codec::{ Input, Output, }; +use sp_runtime::DispatchError; use std::{ collections::{ HashMap, @@ -77,6 +78,20 @@ pub enum EventsError { /// Type size unavailable. #[error("Type Sizes Unavailable: {0:?}")] TypeSizeUnavailable(String), + /// Dispatch error. + #[error("Dispatch error: {0:?}")] + Dispatch(WrapDispatchError), +} + +/// DispatchError doesn't implement std::error::Error. +#[derive(Debug, Error)] +#[error("{0:?}")] +pub struct WrapDispatchError(pub DispatchError); + +impl From for EventsError { + fn from(error: DispatchError) -> Self { + Self::Dispatch(WrapDispatchError(error)) + } } /// Event decoder. @@ -186,6 +201,10 @@ impl EventsDecoder { // PhantomData is size 0 return Ok(()) } + if name.contains("DispatchError") { + let error = DispatchError::decode(input)?; + return Err(error.into()) + } if let Some(size) = self.type_sizes.get(name) { let mut buf = vec![0; *size]; input.read(&mut buf)?;