Skip to content

Commit

Permalink
Handle runtime errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
dvc94ch committed May 4, 2020
1 parent 9e2784d commit 1c40fd2
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use codec::{
Input,
Output,
};
use sp_runtime::DispatchError;
use std::{
collections::{
HashMap,
Expand Down Expand Up @@ -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<DispatchError> for EventsError {
fn from(error: DispatchError) -> Self {
Self::Dispatch(WrapDispatchError(error))
}
}

/// Event decoder.
Expand Down Expand Up @@ -186,6 +201,10 @@ impl<T: System> EventsDecoder<T> {
// 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)?;
Expand Down

0 comments on commit 1c40fd2

Please sign in to comment.