libimagnotes: Replace error code with code generator macro
This commit is contained in:
parent
841d26fdd0
commit
c730cce83b
3 changed files with 10 additions and 80 deletions
|
@ -11,6 +11,9 @@ toml = "0.1.25"
|
||||||
[dependencies.libimagstore]
|
[dependencies.libimagstore]
|
||||||
path = "../libimagstore"
|
path = "../libimagstore"
|
||||||
|
|
||||||
|
[dependencies.libimagerror]
|
||||||
|
path = "../libimagerror"
|
||||||
|
|
||||||
[dependencies.libimagrt]
|
[dependencies.libimagrt]
|
||||||
path = "../libimagrt"
|
path = "../libimagrt"
|
||||||
|
|
||||||
|
|
|
@ -2,84 +2,10 @@ use std::error::Error;
|
||||||
use std::fmt::Error as FmtError;
|
use std::fmt::Error as FmtError;
|
||||||
use std::fmt::{Display, Formatter};
|
use std::fmt::{Display, Formatter};
|
||||||
|
|
||||||
/**
|
generate_error_types!(NoteError, NoteErrorKind,
|
||||||
* Kind of error
|
StoreWriteError => "Error writing store",
|
||||||
*/
|
StoreReadError => "Error reading store",
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
HeaderTypeError => "Header type error",
|
||||||
pub enum NoteErrorKind {
|
NoteToEntryConversion => "Error converting Note instance to Entry instance"
|
||||||
StoreWriteError,
|
);
|
||||||
StoreReadError,
|
|
||||||
HeaderTypeError,
|
|
||||||
NoteToEntryConversion,
|
|
||||||
// Nothing here yet
|
|
||||||
}
|
|
||||||
|
|
||||||
fn note_error_type_as_str(e: &NoteErrorKind) -> &'static str {
|
|
||||||
match *e {
|
|
||||||
NoteErrorKind::StoreWriteError => "Error writing store",
|
|
||||||
NoteErrorKind::StoreReadError => "Error reading store",
|
|
||||||
NoteErrorKind::HeaderTypeError => "Header type error",
|
|
||||||
NoteErrorKind::NoteToEntryConversion => "Error converting Note instance to Entry instance",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Display for NoteErrorKind {
|
|
||||||
|
|
||||||
fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
|
|
||||||
try!(write!(fmt, "{}", note_error_type_as_str(self)));
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Store error type
|
|
||||||
*/
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct NoteError {
|
|
||||||
err_type: NoteErrorKind,
|
|
||||||
cause: Option<Box<Error>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl NoteError {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Build a new NoteError from an NoteErrorKind, optionally with cause
|
|
||||||
*/
|
|
||||||
pub fn new(errtype: NoteErrorKind, cause: Option<Box<Error>>) -> NoteError {
|
|
||||||
NoteError {
|
|
||||||
err_type: errtype,
|
|
||||||
cause: cause,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the error type of this NoteError
|
|
||||||
*/
|
|
||||||
pub fn err_type(&self) -> NoteErrorKind {
|
|
||||||
self.err_type
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Display for NoteError {
|
|
||||||
|
|
||||||
fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
|
|
||||||
try!(write!(fmt, "[{}]", note_error_type_as_str(&self.err_type)));
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Error for NoteError {
|
|
||||||
|
|
||||||
fn description(&self) -> &str {
|
|
||||||
note_error_type_as_str(&self.err_type)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn cause(&self) -> Option<&Error> {
|
|
||||||
self.cause.as_ref().map(|e| &**e)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ extern crate toml;
|
||||||
|
|
||||||
extern crate libimagrt;
|
extern crate libimagrt;
|
||||||
#[macro_use] extern crate libimagstore;
|
#[macro_use] extern crate libimagstore;
|
||||||
|
#[macro_use] extern crate libimagerror;
|
||||||
extern crate libimagentrytag;
|
extern crate libimagentrytag;
|
||||||
|
|
||||||
module_entry_path_mod!("notes", "0.1.0");
|
module_entry_path_mod!("notes", "0.1.0");
|
||||||
|
|
Loading…
Reference in a new issue