diff --git a/light-node/src/error.rs b/light-node/src/error.rs index 094799b62..9d59844f4 100644 --- a/light-node/src/error.rs +++ b/light-node/src/error.rs @@ -1,8 +1,9 @@ //! Error types -use std::io; use std::net; +use anomaly::{BoxError, Context}; + /// Error type pub type Error = anomaly::Error; @@ -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 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) -> Context { + Context::new(self, Some(source.into())) } } diff --git a/light-node/src/rpc.rs b/light-node/src/rpc.rs index 544dcb4eb..f6b190fe2 100644 --- a/light-node/src/rpc.rs +++ b/light-node/src/rpc.rs @@ -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();