imag-store: Rewrite error handling

This commit is contained in:
Matthias Beyer 2017-09-03 20:41:43 +02:00
parent 936a314efa
commit 54219cb6fa
3 changed files with 10 additions and 8 deletions

View file

@ -38,6 +38,7 @@ use libimagutil::debug_result::*;
use error::StoreError; use error::StoreError;
use error::StoreErrorKind; use error::StoreErrorKind;
use error::ResultExt;
use util::build_toml_header; use util::build_toml_header;
type Result<T> = RResult<T, StoreError>; type Result<T> = RResult<T, StoreError>;
@ -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<()> { fn create_from_source(rt: &Runtime, matches: &ArgMatches, path: &StoreId) -> Result<()> {
let content = matches let content = matches
.value_of("from-raw") .value_of("from-raw")
.ok_or(StoreError::new(StoreErrorKind::NoCommandlineCall, None)) .ok_or(StoreError::from_kind(StoreErrorKind::NoCommandlineCall))
.map(string_from_raw_src); .map(string_from_raw_src);
if content.is_err() { if content.is_err() {
@ -133,7 +134,7 @@ fn create_from_source(rt: &Runtime, matches: &ArgMatches, path: &StoreId) -> Res
r r
}) })
.map_dbg_err(|e| format!("Error storing entry: {:?}", e)) .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, fn create_with_content_and_header(rt: &Runtime,
@ -157,7 +158,7 @@ fn create_with_content_and_header(rt: &Runtime,
debug!("New header set"); 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 { fn string_from_raw_src(raw_src: &str) -> String {

View file

@ -17,6 +17,10 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
// //
use std::error::Error;
use libimagerror::into::IntoError;
error_chain! { error_chain! {
types { types {
StoreError, StoreErrorKind, ResultExt, Result; StoreError, StoreErrorKind, ResultExt, Result;
@ -36,9 +40,6 @@ error_chain! {
} }
} }
pub use self::error::StoreError;
pub use self::error::StoreErrorKind;
impl IntoError for StoreErrorKind { impl IntoError for StoreErrorKind {
type Target = StoreError; type Target = StoreError;
@ -46,7 +47,7 @@ impl IntoError for StoreErrorKind {
StoreError::from_kind(self) StoreError::from_kind(self)
} }
fn into_error_with_cause(self, cause: Box<Error>) -> Self::Target { fn into_error_with_cause(self, _: Box<Error>) -> Self::Target {
StoreError::from_kind(self) StoreError::from_kind(self)
} }
} }

View file

@ -41,7 +41,7 @@ extern crate toml;
extern crate libimagrt; extern crate libimagrt;
extern crate libimagstore; extern crate libimagstore;
extern crate libimagutil; extern crate libimagutil;
#[macro_use] extern crate libimagerror; extern crate libimagerror;
use libimagrt::setup::generate_runtime_setup; use libimagrt::setup::generate_runtime_setup;