From 54219cb6fab458ee43e84eeb25ba4ba1c73b37ea Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 3 Sep 2017 20:41:43 +0200 Subject: [PATCH] imag-store: Rewrite error handling --- bin/core/imag-store/src/create.rs | 7 ++++--- bin/core/imag-store/src/error.rs | 9 +++++---- bin/core/imag-store/src/main.rs | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/bin/core/imag-store/src/create.rs b/bin/core/imag-store/src/create.rs index f434ba75..d4fb9421 100644 --- a/bin/core/imag-store/src/create.rs +++ b/bin/core/imag-store/src/create.rs @@ -38,6 +38,7 @@ use libimagutil::debug_result::*; use error::StoreError; use error::StoreErrorKind; +use error::ResultExt; use util::build_toml_header; type Result = RResult; @@ -110,7 +111,7 @@ fn create_from_cli_spec(rt: &Runtime, matches: &ArgMatches, path: &StoreId) -> R fn create_from_source(rt: &Runtime, matches: &ArgMatches, path: &StoreId) -> Result<()> { let content = matches .value_of("from-raw") - .ok_or(StoreError::new(StoreErrorKind::NoCommandlineCall, None)) + .ok_or(StoreError::from_kind(StoreErrorKind::NoCommandlineCall)) .map(string_from_raw_src); if content.is_err() { @@ -133,7 +134,7 @@ fn create_from_source(rt: &Runtime, matches: &ArgMatches, path: &StoreId) -> Res r }) .map_dbg_err(|e| format!("Error storing entry: {:?}", e)) - .map_err(|serr| StoreError::new(StoreErrorKind::BackendError, Some(Box::new(serr)))) + .chain_err(|| StoreErrorKind::BackendError) } fn create_with_content_and_header(rt: &Runtime, @@ -157,7 +158,7 @@ fn create_with_content_and_header(rt: &Runtime, debug!("New header set"); } }) - .map_err(|e| StoreError::new(StoreErrorKind::BackendError, Some(Box::new(e)))) + .chain_err(|| StoreErrorKind::BackendError) } fn string_from_raw_src(raw_src: &str) -> String { diff --git a/bin/core/imag-store/src/error.rs b/bin/core/imag-store/src/error.rs index 163ae344..3e4f5d02 100644 --- a/bin/core/imag-store/src/error.rs +++ b/bin/core/imag-store/src/error.rs @@ -17,6 +17,10 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // +use std::error::Error; + +use libimagerror::into::IntoError; + error_chain! { types { StoreError, StoreErrorKind, ResultExt, Result; @@ -36,9 +40,6 @@ error_chain! { } } -pub use self::error::StoreError; -pub use self::error::StoreErrorKind; - impl IntoError for StoreErrorKind { type Target = StoreError; @@ -46,7 +47,7 @@ impl IntoError for StoreErrorKind { StoreError::from_kind(self) } - fn into_error_with_cause(self, cause: Box) -> Self::Target { + fn into_error_with_cause(self, _: Box) -> Self::Target { StoreError::from_kind(self) } } diff --git a/bin/core/imag-store/src/main.rs b/bin/core/imag-store/src/main.rs index 45212628..434c84a8 100644 --- a/bin/core/imag-store/src/main.rs +++ b/bin/core/imag-store/src/main.rs @@ -41,7 +41,7 @@ extern crate toml; extern crate libimagrt; extern crate libimagstore; extern crate libimagutil; -#[macro_use] extern crate libimagerror; +extern crate libimagerror; use libimagrt::setup::generate_runtime_setup;