libimagrt: Replace error code with code generator macro
This commit is contained in:
parent
c730cce83b
commit
f27b114f85
3 changed files with 9 additions and 54 deletions
|
@ -21,3 +21,6 @@ path = "../libimagstorestdhook"
|
||||||
[dependencies.libimagutil]
|
[dependencies.libimagutil]
|
||||||
path = "../libimagutil"
|
path = "../libimagutil"
|
||||||
|
|
||||||
|
[dependencies.libimagerror]
|
||||||
|
path = "../libimagerror"
|
||||||
|
|
||||||
|
|
|
@ -4,60 +4,11 @@ use std::fmt::Formatter;
|
||||||
use std::fmt::Error as FmtError;
|
use std::fmt::Error as FmtError;
|
||||||
use std::io::Error as IOError;
|
use std::io::Error as IOError;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone, Copy)]
|
generate_error_types!(RuntimeError, RuntimeErrorKind,
|
||||||
pub enum RuntimeErrorKind {
|
Instantiate => "Could not instantiate",
|
||||||
Instantiate,
|
IOError => "IO Error",
|
||||||
IOError,
|
ProcessExitFailure => "Process exited with failure"
|
||||||
ProcessExitFailure,
|
);
|
||||||
|
|
||||||
// more?
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct RuntimeError {
|
|
||||||
kind: RuntimeErrorKind,
|
|
||||||
cause: Option<Box<Error>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RuntimeError {
|
|
||||||
|
|
||||||
pub fn new(kind: RuntimeErrorKind, cause: Option<Box<Error>>) -> RuntimeError {
|
|
||||||
RuntimeError {
|
|
||||||
kind: kind,
|
|
||||||
cause: cause,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
fn runtime_error_kind_as_str(e: &RuntimeErrorKind) -> &'static str {
|
|
||||||
match *e {
|
|
||||||
RuntimeErrorKind::Instantiate => "Could not instantiate",
|
|
||||||
RuntimeErrorKind::IOError => "IO Error",
|
|
||||||
RuntimeErrorKind::ProcessExitFailure => "Process exited with failure",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Display for RuntimeError {
|
|
||||||
|
|
||||||
fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
|
|
||||||
try!(write!(fmt, "{}", runtime_error_kind_as_str(&self.kind)));
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Error for RuntimeError {
|
|
||||||
|
|
||||||
fn description(&self) -> &str {
|
|
||||||
runtime_error_kind_as_str(&self.kind)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn cause(&self) -> Option<&Error> {
|
|
||||||
self.cause.as_ref().map(|e| &**e)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<IOError> for RuntimeError {
|
impl From<IOError> for RuntimeError {
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ extern crate toml;
|
||||||
extern crate libimagstore;
|
extern crate libimagstore;
|
||||||
extern crate libimagstorestdhook;
|
extern crate libimagstorestdhook;
|
||||||
extern crate libimagutil;
|
extern crate libimagutil;
|
||||||
|
#[macro_use] extern crate libimagerror;
|
||||||
|
|
||||||
mod configuration;
|
mod configuration;
|
||||||
mod logger;
|
mod logger;
|
||||||
|
|
Loading…
Reference in a new issue