Skip to content

Commit

Permalink
Attach underlying IO error to light node Kind::Io error (#413)
Browse files Browse the repository at this point in the history
  • Loading branch information
romac authored Jul 7, 2020
1 parent 1b46e32 commit 142796b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions light-node/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//! Error types
use std::io;
use std::net;

use anomaly::{BoxError, Context};

/// Error type
pub type Error = anomaly::Error<Kind>;

Expand All @@ -18,12 +19,14 @@ pub enum Kind {
Config,

/// Input/output error
#[error("i/o error: {0}")]
Io(String),
#[error("i/o error")]
Io,
}

impl From<io::Error> for Kind {
fn from(err: io::Error) -> Self {
Self::Io(format!("{}", err))
impl Kind {
/// Add additional context (i.e. include a source error and capture a backtrace).
/// You can convert the resulting `Context` into an `Error` by calling `.into()`.
pub fn context(self, source: impl Into<BoxError>) -> Context<Self> {
Context::new(self, Some(source.into()))
}
}
2 changes: 1 addition & 1 deletion light-node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ where
AccessControlAllowOrigin::Any,
]))
.start_http(&addr.parse().map_err(error::Kind::from)?)
.map_err(error::Kind::from)?;
.map_err(|e| error::Kind::Io.context(e))?;

srv.wait();

Expand Down

0 comments on commit 142796b

Please sign in to comment.