diff --git a/imag-store/Cargo.toml b/imag-store/Cargo.toml index 0deba5a0..6c244322 100644 --- a/imag-store/Cargo.toml +++ b/imag-store/Cargo.toml @@ -19,3 +19,6 @@ path = "../libimagrt" [dependencies.libimagutil] path = "../libimagutil" +[dependencies.libimagerror] +path = "../libimagerror" + diff --git a/imag-store/src/error.rs b/imag-store/src/error.rs index 30c9c8b5..472070f2 100644 --- a/imag-store/src/error.rs +++ b/imag-store/src/error.rs @@ -1,75 +1,9 @@ use std::error::Error; use std::fmt::Error as FmtError; -use std::clone::Clone; use std::fmt::{Display, Formatter}; -#[derive(Clone, Copy, Debug, PartialEq)] -/// Kind of store error -pub enum StoreErrorKind { - BackendError, - NoCommandlineCall, - // maybe more -} - -fn store_error_type_as_str(e: &StoreErrorKind) -> &'static str { - match *e { - StoreErrorKind::BackendError => "Backend Error", - StoreErrorKind::NoCommandlineCall => "No commandline call", - } -} - -impl Display for StoreErrorKind { - - fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> { - try!(write!(fmt, "{}", store_error_type_as_str(self))); - Ok(()) - } - -} - -#[derive(Debug)] -pub struct StoreError { - err_type: StoreErrorKind, - cause: Option>, -} - -impl StoreError { - - ///Build a new StoreError from an StoreErrorKind, optionally with cause - pub fn new(errtype: StoreErrorKind, cause: Option>) - -> StoreError - { - StoreError { - err_type: errtype, - cause: cause, - } - } - - /// Get the error type of this StoreError - pub fn err_type(&self) -> StoreErrorKind { - self.err_type - } - -} - -impl Display for StoreError { - - fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> { - try!(write!(fmt, "[{}]", store_error_type_as_str(&self.err_type.clone()))); - Ok(()) - } - -} - -impl Error for StoreError { - - fn description(&self) -> &str { - store_error_type_as_str(&self.err_type) - } - - fn cause(&self) -> Option<&Error> { - self.cause.as_ref().map(|e| &**e) - } - -} +generate_error_types!(StoreError, StoreErrorKind, + BackendError => "Backend Error", + NoCommandlineCall => "No commandline call" +); diff --git a/imag-store/src/main.rs b/imag-store/src/main.rs index a1e9e09a..fd0a2c4d 100644 --- a/imag-store/src/main.rs +++ b/imag-store/src/main.rs @@ -22,6 +22,7 @@ extern crate toml; extern crate libimagrt; extern crate libimagstore; extern crate libimagutil; +#[macro_use] extern crate libimagerror; use libimagrt::runtime::Runtime; use std::process::exit;