Merge pull request #410 from matthiasbeyer/libimagerror/init

Libimagerror/init
This commit is contained in:
Matthias Beyer 2016-05-17 20:25:36 +02:00
commit 38a8772d69
37 changed files with 261 additions and 1008 deletions

View File

@ -19,3 +19,6 @@ path = "../libimagrt"
[dependencies.libimagutil]
path = "../libimagutil"
[dependencies.libimagerror]
path = "../libimagerror"

View File

@ -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<Box<Error>>,
}
impl StoreError {
///Build a new StoreError from an StoreErrorKind, optionally with cause
pub fn new(errtype: StoreErrorKind, cause: Option<Box<Error>>)
-> 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"
);

View File

@ -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;

View File

@ -21,3 +21,6 @@ path = "../libimagrt"
[dependencies.libimagutil]
path = "../libimagutil"
[dependencies.libimagerror]
path = "../libimagerror"

View File

@ -2,85 +2,10 @@ use std::error::Error;
use std::fmt::Error as FmtError;
use std::fmt::{Display, Formatter};
/**
* Kind of store error
*/
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum ViewErrorKind {
StoreError,
NoVersion,
PatternError,
GlobBuildError,
}
fn view_error_type_as_str(e: &ViewErrorKind) -> &'static str {
match *e {
ViewErrorKind::StoreError => "Store error",
ViewErrorKind::NoVersion => "No version specified",
ViewErrorKind::PatternError => "Error in Pattern",
ViewErrorKind::GlobBuildError => "Could not build glob() Argument",
}
}
impl Display for ViewErrorKind {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
try!(write!(fmt, "{}", view_error_type_as_str(self)));
Ok(())
}
}
/**
* View error type
*/
#[derive(Debug)]
pub struct ViewError {
err_type: ViewErrorKind,
cause: Option<Box<Error>>,
}
impl ViewError {
/**
* Build a new ViewError from an ViewErrorKind, optionally with cause
*/
pub fn new(errtype: ViewErrorKind, cause: Option<Box<Error>>)
-> ViewError
{
ViewError {
err_type: errtype,
cause: cause,
}
}
/**
* Get the error type of this ViewError
*/
pub fn err_type(&self) -> ViewErrorKind {
self.err_type
}
}
impl Display for ViewError {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
try!(write!(fmt, "[{}]", view_error_type_as_str(&self.err_type)));
Ok(())
}
}
impl Error for ViewError {
fn description(&self) -> &str {
view_error_type_as_str(&self.err_type)
}
fn cause(&self) -> Option<&Error> {
self.cause.as_ref().map(|e| &**e)
}
}
generate_error_types!(ViewError, ViewErrorKind,
StoreError => "Store error",
NoVersion => "No version specified",
PatternError => "Error in Pattern",
GlobBuildError => "Could not build glob() Argument"
);

View File

@ -23,6 +23,7 @@ extern crate toml;
extern crate libimagrt;
extern crate libimagstore;
extern crate libimagutil;
#[macro_use] extern crate libimagerror;
use std::result::Result as RResult;
use std::process::exit;

View File

@ -11,3 +11,6 @@ semver = "0.2"
[dependencies.libimagstore]
path = "../libimagstore"
[dependencies.libimagerror]
path = "../libimagerror"

View File

@ -2,85 +2,10 @@ use std::error::Error;
use std::fmt::Error as FmtError;
use std::fmt::{Display, Formatter};
/**
* Kind of error
*/
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum CounterErrorKind {
StoreReadError,
StoreWriteError,
HeaderTypeError,
HeaderFieldMissingError,
}
fn counter_error_type_as_str(e: &CounterErrorKind) -> &'static str {
match *e {
CounterErrorKind::StoreReadError => "Store read error",
CounterErrorKind::StoreWriteError => "Store write error",
CounterErrorKind::HeaderTypeError => "Header type error",
CounterErrorKind::HeaderFieldMissingError => "Header field missing error",
}
}
impl Display for CounterErrorKind {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
try!(write!(fmt, "{}", counter_error_type_as_str(self)));
Ok(())
}
}
/**
* Store error type
*/
#[derive(Debug)]
pub struct CounterError {
err_type: CounterErrorKind,
cause: Option<Box<Error>>,
}
impl CounterError {
/**
* Build a new CounterError from an CounterErrorKind, optionally with cause
*/
pub fn new(errtype: CounterErrorKind, cause: Option<Box<Error>>)
-> CounterError
{
CounterError {
err_type: errtype,
cause: cause,
}
}
/**
* Get the error type of this CounterError
*/
pub fn err_type(&self) -> CounterErrorKind {
self.err_type
}
}
impl Display for CounterError {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
try!(write!(fmt, "[{}]", counter_error_type_as_str(&self.err_type)));
Ok(())
}
}
impl Error for CounterError {
fn description(&self) -> &str {
counter_error_type_as_str(&self.err_type)
}
fn cause(&self) -> Option<&Error> {
self.cause.as_ref().map(|e| &**e)
}
}
generate_error_types!(CounterError, CounterErrorKind,
StoreReadError => "Store read error",
StoreWriteError => "Store write error",
HeaderTypeError => "Header type error",
HeaderFieldMissingError => "Header field missing error"
);

View File

@ -17,6 +17,7 @@ extern crate toml;
#[macro_use] extern crate semver;
#[macro_use] extern crate libimagstore;
#[macro_use] extern crate libimagerror;
module_entry_path_mod!("counter", "0.1.0");

View File

@ -14,3 +14,6 @@ rust-crypto = "0.2.35"
[dependencies.libimagstore]
path = "../libimagstore"
[dependencies.libimagerror]
path = "../libimagerror"

View File

@ -2,89 +2,14 @@ use std::error::Error;
use std::fmt::Error as FmtError;
use std::fmt::{Display, Formatter};
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum LinkErrorKind {
EntryHeaderReadError,
EntryHeaderWriteError,
ExistingLinkTypeWrong,
LinkTargetDoesNotExist,
InternalConversionError,
InvalidUri,
StoreReadError,
StoreWriteError,
}
generate_error_types!(LinkError, LinkErrorKind,
EntryHeaderReadError => "Error while reading an entry header",
EntryHeaderWriteError => "Error while writing an entry header",
ExistingLinkTypeWrong => "Existing link entry has wrong type",
LinkTargetDoesNotExist => "Link target does not exist in the store",
InternalConversionError => "Error while converting values internally",
InvalidUri => "URI is not valid",
StoreReadError => "Store read error",
StoreWriteError => "Store write error"
);
fn link_error_type_as_str(e: &LinkErrorKind) -> &'static str {
match *e {
LinkErrorKind::EntryHeaderReadError
=> "Error while reading an entry header",
LinkErrorKind::EntryHeaderWriteError
=> "Error while writing an entry header",
LinkErrorKind::ExistingLinkTypeWrong
=> "Existing link entry has wrong type",
LinkErrorKind::LinkTargetDoesNotExist
=> "Link target does not exist in the store",
LinkErrorKind::InternalConversionError
=> "Error while converting values internally",
LinkErrorKind::InvalidUri
=> "URI is not valid",
LinkErrorKind::StoreReadError
=> "Store read error",
LinkErrorKind::StoreWriteError
=> "Store write error",
}
}
impl Display for LinkErrorKind {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
try!(write!(fmt, "{}", link_error_type_as_str(self)));
Ok(())
}
}
#[derive(Debug)]
pub struct LinkError {
kind: LinkErrorKind,
cause: Option<Box<Error>>,
}
impl LinkError {
pub fn new(errtype: LinkErrorKind, cause: Option<Box<Error>>) -> LinkError {
LinkError {
kind: errtype,
cause: cause,
}
}
}
impl Display for LinkError {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
try!(write!(fmt, "[{}]", link_error_type_as_str(&self.kind)));
Ok(())
}
}
impl Error for LinkError {
fn description(&self) -> &str {
link_error_type_as_str(&self.kind)
}
fn cause(&self) -> Option<&Error> {
self.cause.as_ref().map(|e| &**e)
}
}

View File

@ -20,6 +20,7 @@ extern crate url;
extern crate crypto;
#[macro_use] extern crate libimagstore;
#[macro_use] extern crate libimagerror;
module_entry_path_mod!("links", "0.1.0");

View File

@ -11,3 +11,6 @@ toml = "0.1.25"
[dependencies.libimagstore]
path = "../libimagstore"
[dependencies.libimagerror]
path = "../libimagerror"

View File

@ -2,83 +2,10 @@ use std::error::Error;
use std::fmt::Error as FmtError;
use std::fmt::{Display, Formatter};
/**
* Kind of error
*/
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum ListErrorKind {
FormatError,
EntryError,
IterationError,
CLIError,
}
fn counter_error_type_as_str(err: &ListErrorKind) -> &'static str{
match *err {
ListErrorKind::FormatError => "FormatError",
ListErrorKind::EntryError => "EntryError",
ListErrorKind::IterationError => "IterationError",
ListErrorKind::CLIError => "No CLI subcommand for listing entries",
}
}
impl Display for ListErrorKind {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
try!(write!(fmt, "{}", counter_error_type_as_str(self)));
Ok(())
}
}
/**
* Store error type
*/
#[derive(Debug)]
pub struct ListError {
err_type: ListErrorKind,
cause: Option<Box<Error>>,
}
impl ListError {
/**
* Build a new ListError from an ListErrorKind, optionally with cause
*/
pub fn new(errtype: ListErrorKind, cause: Option<Box<Error>>) -> ListError {
ListError {
err_type: errtype,
cause: cause,
}
}
/**
* Get the error type of this ListError
*/
pub fn err_type(&self) -> ListErrorKind {
self.err_type
}
}
impl Display for ListError {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
try!(write!(fmt, "[{}]", counter_error_type_as_str(&self.err_type)));
Ok(())
}
}
impl Error for ListError {
fn description(&self) -> &str {
counter_error_type_as_str(&self.err_type)
}
fn cause(&self) -> Option<&Error> {
self.cause.as_ref().map(|e| &**e)
}
}
generate_error_types!(ListError, ListErrorKind,
FormatError => "FormatError",
EntryError => "EntryError",
IterationError => "IterationError",
CLIError => "No CLI subcommand for listing entries"
);

View File

@ -19,6 +19,7 @@ extern crate clap;
extern crate toml;
extern crate libimagstore;
#[macro_use] extern crate libimagerror;
pub mod cli;
pub mod error;

View File

@ -13,3 +13,6 @@ itertools = "0.4"
[dependencies.libimagstore]
path = "../libimagstore"
[dependencies.libimagerror]
path = "../libimagerror"

View File

@ -2,67 +2,10 @@ use std::error::Error;
use std::fmt::Error as FmtError;
use std::fmt::{Display, Formatter};
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum TagErrorKind {
TagTypeError,
HeaderReadError,
HeaderWriteError,
NotATag,
}
fn tag_error_type_as_str(e: &TagErrorKind) -> &'static str {
match *e {
TagErrorKind::TagTypeError => "Entry Header Tag Type wrong",
TagErrorKind::HeaderReadError => "Error while reading entry header",
TagErrorKind::HeaderWriteError => "Error while writing entry header",
TagErrorKind::NotATag => "String is not a tag",
}
}
impl Display for TagErrorKind {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
try!(write!(fmt, "{}", tag_error_type_as_str(self)));
Ok(())
}
}
#[derive(Debug)]
pub struct TagError {
kind: TagErrorKind,
cause: Option<Box<Error>>,
}
impl TagError {
pub fn new(errtype: TagErrorKind, cause: Option<Box<Error>>) -> TagError {
TagError {
kind: errtype,
cause: cause,
}
}
}
impl Display for TagError {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
try!(write!(fmt, "[{}]", tag_error_type_as_str(&self.kind)));
Ok(())
}
}
impl Error for TagError {
fn description(&self) -> &str {
tag_error_type_as_str(&self.kind)
}
fn cause(&self) -> Option<&Error> {
self.cause.as_ref().map(|e| &**e)
}
}
generate_error_types!(TagError, TagErrorKind,
TagTypeError => "Entry Header Tag Type wrong",
HeaderReadError => "Error while reading entry header",
HeaderWriteError => "Error while writing entry header",
NotATag => "String is not a tag"
);

View File

@ -19,6 +19,7 @@ extern crate regex;
extern crate toml;
extern crate libimagstore;
#[macro_use] extern crate libimagerror;
pub mod error;
pub mod exec;

View File

@ -8,3 +8,6 @@ authors = ["Matthias Beyer <mail@beyermatthias.de>"]
[dependencies.libimagstore]
path = "../libimagstore"
[dependencies.libimagerror]
path = "../libimagerror"

View File

@ -2,78 +2,7 @@ use std::error::Error;
use std::fmt::Error as FmtError;
use std::fmt::{Display, Formatter};
/**
* Kind of error
*/
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum ViewErrorKind {
}
fn counter_error_type_as_str(e: &ViewErrorKind) -> &'static str {
match e {
_ => "",
}
}
impl Display for ViewErrorKind {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
try!(write!(fmt, "{}", counter_error_type_as_str(self)));
Ok(())
}
}
/**
* Store error type
*/
#[derive(Debug)]
pub struct ViewError {
err_type: ViewErrorKind,
cause: Option<Box<Error>>,
}
impl ViewError {
/**
* Build a new ViewError from an ViewErrorKind, optionally with cause
*/
pub fn new(errtype: ViewErrorKind, cause: Option<Box<Error>>)
-> ViewError
{
ViewError {
err_type: errtype,
cause: cause,
}
}
/**
* Get the error type of this ViewError
*/
pub fn err_type(&self) -> ViewErrorKind {
self.err_type
}
}
impl Display for ViewError {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
try!(write!(fmt, "[{}]", counter_error_type_as_str(&self.err_type)));
Ok(())
}
}
impl Error for ViewError {
fn description(&self) -> &str {
counter_error_type_as_str(&self.err_type)
}
fn cause(&self) -> Option<&Error> {
self.cause.as_ref().map(|e| &**e)
}
}
generate_error_types!(ViewError, ViewErrorKind,
Unknown => "Unknown view error"
);

View File

@ -15,6 +15,7 @@
)]
extern crate libimagstore;
#[macro_use] extern crate libimagerror;
pub mod error;
pub mod builtin;

6
libimagerror/Cargo.toml Normal file
View File

@ -0,0 +1,6 @@
[package]
name = "libimagerror"
version = "0.1.0"
authors = ["Matthias Beyer <mail@beyermatthias.de>"]
[dependencies]

View File

@ -0,0 +1,113 @@
#[macro_export]
macro_rules! generate_error_types {
(
$name: ident,
$kindname: ident,
$($kind:ident => $string:expr),*
) => {
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum $kindname {
$( $kind ),*
}
impl Display for $kindname {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
let s = match *self {
$( $kindname::$kind => $string ),*
};
try!(write!(fmt, "{}", s));
Ok(())
}
}
#[derive(Debug)]
pub struct $name {
err_type: $kindname,
cause: Option<Box<Error>>,
}
impl $name {
pub fn new(errtype: $kindname, cause: Option<Box<Error>>) -> $name {
$name {
err_type: errtype,
cause: cause,
}
}
pub fn err_type(&self) -> $kindname {
self.err_type
}
}
impl Display for $name {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
try!(write!(fmt, "[{}]", self.err_type));
Ok(())
}
}
impl Error for $name {
fn description(&self) -> &str {
match self.err_type {
$( $kindname::$kind => $string ),*
}
}
fn cause(&self) -> Option<&Error> {
self.cause.as_ref().map(|e| &**e)
}
}
}
}
#[cfg(test)]
mod test {
use std::error::Error;
use std::fmt::Error as FmtError;
use std::fmt::{Display, Formatter};
generate_error_types!(TestError, TestErrorKind,
TestErrorKindA => "testerrorkind a",
TestErrorKindB => "testerrorkind B");
#[test]
fn test_a() {
let kind = TestErrorKind::TestErrorKindA;
assert_eq!(String::from("testerrorkind a"), format!("{}", kind));
let e = TestError::new(kind, None);
assert_eq!(String::from("[testerrorkind a]"), format!("{}", e));
}
#[test]
fn test_b() {
let kind = TestErrorKind::TestErrorKindB;
assert_eq!(String::from("testerrorkind B"), format!("{}", kind));
let e = TestError::new(kind, None);
assert_eq!(String::from("[testerrorkind B]"), format!("{}", e));
}
#[test]
fn test_ab() {
let kinda = TestErrorKind::TestErrorKindA;
let kindb = TestErrorKind::TestErrorKindB;
assert_eq!(String::from("testerrorkind a"), format!("{}", kinda));
assert_eq!(String::from("testerrorkind B"), format!("{}", kindb));
let e = TestError::new(kinda, Some(Box::new(TestError::new(kindb, None))));
assert_eq!(String::from("[testerrorkind a]"), format!("{}", e));
assert_eq!(TestErrorKind::TestErrorKindA, e.err_type());
assert_eq!(String::from("[testerrorkind B]"), format!("{}", e.cause().unwrap()));
}
}

1
libimagerror/src/lib.rs Normal file
View File

@ -0,0 +1 @@
pub mod error_gen;

View File

@ -20,3 +20,6 @@ path = "../libimagentryfilter"
[dependencies.libimagutil]
path = "../libimagutil"
[dependencies.libimagerror]
path = "../libimagerror"

View File

@ -2,76 +2,7 @@ use std::error::Error;
use std::fmt::Error as FmtError;
use std::fmt::{Display, Formatter};
/**
* Kind of error
*/
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum InteractionErrorKind {
Unknown
}
fn interaction_error_type_as_str(e: &InteractionErrorKind) -> &'static str {
match *e {
InteractionErrorKind::Unknown => "Unknown Error",
}
}
impl Display for InteractionErrorKind {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
try!(write!(fmt, "{}", interaction_error_type_as_str(self)));
Ok(())
}
}
#[derive(Debug)]
pub struct InteractionError {
err_type: InteractionErrorKind,
cause: Option<Box<Error>>,
}
impl InteractionError {
/**
* Build a new InteractionError from an InteractionErrorKind, optionally with cause
*/
pub fn new(errtype: InteractionErrorKind, cause: Option<Box<Error>>)
-> InteractionError
{
InteractionError {
err_type: errtype,
cause: cause,
}
}
/**
* Get the error type of this InteractionError
*/
pub fn err_type(&self) -> InteractionErrorKind {
self.err_type
}
}
impl Display for InteractionError {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
try!(write!(fmt, "[{}]", interaction_error_type_as_str(&self.err_type)));
Ok(())
}
}
impl Error for InteractionError {
fn description(&self) -> &str {
interaction_error_type_as_str(&self.err_type)
}
fn cause(&self) -> Option<&Error> {
self.cause.as_ref().map(|e| &**e)
}
}
generate_error_types!(InteractionError, InteractionErrorKind,
Unknown => "Unknown Error"
);

View File

@ -8,6 +8,7 @@ extern crate regex;
extern crate libimagentryfilter;
extern crate libimagstore;
#[macro_use] extern crate libimagutil;
#[macro_use] extern crate libimagerror;
pub mod ask;
pub mod error;

View File

@ -11,6 +11,9 @@ toml = "0.1.25"
[dependencies.libimagstore]
path = "../libimagstore"
[dependencies.libimagerror]
path = "../libimagerror"
[dependencies.libimagrt]
path = "../libimagrt"

View File

@ -2,84 +2,10 @@ use std::error::Error;
use std::fmt::Error as FmtError;
use std::fmt::{Display, Formatter};
/**
* Kind of error
*/
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum NoteErrorKind {
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)
}
}
generate_error_types!(NoteError, NoteErrorKind,
StoreWriteError => "Error writing store",
StoreReadError => "Error reading store",
HeaderTypeError => "Header type error",
NoteToEntryConversion => "Error converting Note instance to Entry instance"
);

View File

@ -20,6 +20,7 @@ extern crate toml;
extern crate libimagrt;
#[macro_use] extern crate libimagstore;
#[macro_use] extern crate libimagerror;
extern crate libimagentrytag;
module_entry_path_mod!("notes", "0.1.0");

View File

@ -21,3 +21,6 @@ path = "../libimagstorestdhook"
[dependencies.libimagutil]
path = "../libimagutil"
[dependencies.libimagerror]
path = "../libimagerror"

View File

@ -4,60 +4,11 @@ use std::fmt::Formatter;
use std::fmt::Error as FmtError;
use std::io::Error as IOError;
#[derive(Debug, PartialEq, Clone, Copy)]
pub enum RuntimeErrorKind {
Instantiate,
IOError,
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)
}
}
generate_error_types!(RuntimeError, RuntimeErrorKind,
Instantiate => "Could not instantiate",
IOError => "IO Error",
ProcessExitFailure => "Process exited with failure"
);
impl From<IOError> for RuntimeError {

View File

@ -26,6 +26,7 @@ extern crate toml;
extern crate libimagstore;
extern crate libimagstorestdhook;
extern crate libimagutil;
#[macro_use] extern crate libimagerror;
mod configuration;
mod logger;

View File

@ -15,6 +15,9 @@ version = "2.0.1"
crossbeam = "0.2.8"
walkdir = "0.1.5"
[dependencies.libimagerror]
path = "../libimagerror"
[dev-dependencies]
tempdir = "0.3.4"
env_logger = "0.3"

View File

@ -1,138 +1,45 @@
use std::error::Error;
use std::fmt::Error as FmtError;
use std::fmt::{Debug, Display, Formatter};
use std::fmt;
use std::fmt::{Display, Formatter};
use std::convert::From;
/**
* Kind of store error
*/
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum StoreErrorKind {
ConfigurationError,
FileError,
IdLocked,
IdNotFound,
OutOfMemory,
FileNotFound,
FileNotCreated,
IoError,
StorePathExists,
StorePathCreate,
LockError,
LockPoisoned,
EntryAlreadyBorrowed,
EntryAlreadyExists,
MalformedEntry,
HeaderPathSyntaxError,
HeaderPathTypeFailure,
HeaderKeyNotFound,
HeaderTypeFailure,
HookRegisterError,
AspectNameNotFoundError,
HookExecutionError,
PreHookExecuteError,
PostHookExecuteError,
StorePathLacksVersion,
GlobError,
EncodingError,
// maybe more
}
generate_error_types!(StoreError, StoreErrorKind,
ConfigurationError => "Store Configuration Error",
FileError => "File Error",
IoError => "IO Error",
IdLocked => "ID locked",
IdNotFound => "ID not found",
OutOfMemory => "Out of Memory",
FileNotFound => "File corresponding to ID not found",
FileNotCreated => "File corresponding to ID could not be created",
StorePathExists => "Store path exists",
StorePathCreate => "Store path create",
LockError => "Error locking datastructure",
LockPoisoned => "The internal Store Lock has been poisoned",
EntryAlreadyBorrowed => "Entry is already borrowed",
EntryAlreadyExists => "Entry already exists",
MalformedEntry => "Entry has invalid formatting, missing header",
HeaderPathSyntaxError => "Syntax error in accessor string",
HeaderPathTypeFailure => "Header has wrong type for path",
HeaderKeyNotFound => "Header Key not found",
HeaderTypeFailure => "Header type is wrong",
HookRegisterError => "Hook register error",
AspectNameNotFoundError => "Aspect name not found",
HookExecutionError => "Hook execution error",
PreHookExecuteError => "Pre-Hook execution error",
PostHookExecuteError => "Post-Hook execution error",
StorePathLacksVersion => "The supplied store path has no version part",
GlobError => "glob() error",
EncodingError => "Encoding error"
);
fn store_error_type_as_str(e: &StoreErrorKind) -> &'static str {
match *e {
StoreErrorKind::ConfigurationError => "Store Configuration Error",
StoreErrorKind::FileError |
StoreErrorKind::IoError => "File Error",
StoreErrorKind::IdLocked => "ID locked",
StoreErrorKind::IdNotFound => "ID not found",
StoreErrorKind::OutOfMemory => "Out of Memory",
StoreErrorKind::FileNotFound => "File corresponding to ID not found",
StoreErrorKind::FileNotCreated => "File corresponding to ID could not be created",
StoreErrorKind::StorePathExists |
StoreErrorKind::StorePathCreate => "Store path create",
StoreErrorKind::LockError => "Error locking datastructure",
StoreErrorKind::LockPoisoned
=> "The internal Store Lock has been poisoned",
StoreErrorKind::EntryAlreadyBorrowed => "Entry is already borrowed",
StoreErrorKind::EntryAlreadyExists => "Entry already exists",
StoreErrorKind::MalformedEntry => "Entry has invalid formatting, missing header",
StoreErrorKind::HeaderPathSyntaxError => "Syntax error in accessor string",
StoreErrorKind::HeaderPathTypeFailure => "Header has wrong type for path",
StoreErrorKind::HeaderKeyNotFound => "Header Key not found",
StoreErrorKind::HeaderTypeFailure => "Header type is wrong",
StoreErrorKind::HookRegisterError => "Hook register error",
StoreErrorKind::AspectNameNotFoundError => "Aspect name not found",
StoreErrorKind::HookExecutionError => "Hook execution error",
StoreErrorKind::PreHookExecuteError => "Pre-Hook execution error",
StoreErrorKind::PostHookExecuteError => "Post-Hook execution error",
StoreErrorKind::StorePathLacksVersion => "The supplied store path has no version part",
StoreErrorKind::GlobError => "glob() error",
StoreErrorKind::EncodingError => "Encoding error",
}
}
impl Display for StoreErrorKind {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
try!(write!(fmt, "{}", store_error_type_as_str(self)));
Ok(())
}
}
/**
* Store error type
*/
#[derive(Debug)]
pub struct StoreError {
err_type: StoreErrorKind,
cause: Option<Box<Error>>,
}
impl StoreError {
/**
* Build a new StoreError from an StoreErrorKind, optionally with cause
*/
pub fn new(errtype: StoreErrorKind, cause: Option<Box<Error>>)
-> 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)));
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!(ParserError, ParserErrorKind,
TOMLParserErrors => "Several TOML-Parser-Errors",
MissingMainSection => "Missing main section",
MissingVersionInfo => "Missing version information in main section",
NonTableInBaseTable => "A non-table was found in the base table",
HeaderInconsistency => "The header is inconsistent"
);
impl From<ParserError> for StoreError {
fn from(ps: ParserError) -> StoreError {
@ -152,64 +59,3 @@ impl From<::std::io::Error> for StoreError {
}
}
#[derive(Clone)]
pub enum ParserErrorKind {
TOMLParserErrors,
MissingMainSection,
MissingVersionInfo,
NonTableInBaseTable,
HeaderInconsistency,
}
pub struct ParserError {
kind: ParserErrorKind,
cause: Option<Box<Error>>,
}
impl ParserError {
pub fn new(k: ParserErrorKind, cause: Option<Box<Error>>) -> ParserError {
ParserError {
kind: k,
cause: cause,
}
}
}
impl Debug for ParserError {
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
try!(write!(f, "{:?}", self.description()));
Ok(())
}
}
impl Display for ParserError {
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
try!(write!(f, "{}", self.description()));
Ok(())
}
}
impl Error for ParserError {
fn description(&self) -> &str {
match self.kind {
ParserErrorKind::TOMLParserErrors => "Several TOML-Parser-Errors",
ParserErrorKind::MissingMainSection => "Missing main section",
ParserErrorKind::MissingVersionInfo => "Missing version information in main section",
ParserErrorKind::NonTableInBaseTable => "A non-table was found in the base table",
ParserErrorKind::HeaderInconsistency => "The header is inconsistent",
}
}
fn cause(&self) -> Option<&Error> {
self.cause.as_ref().map(|e| &**e)
}
}

View File

@ -3,14 +3,10 @@ use std::fmt::Error as FmtError;
use std::fmt::{Display, Formatter};
use std::convert::Into;
/**
* Kind of error
*/
#[derive(Clone, Copy, Debug)]
pub enum HookErrorKind {
HookExecutionError,
AccessTypeViolation,
}
generate_error_types!(HookError, HookErrorKind,
HookExecutionError => "Hook exec error",
AccessTypeViolation => "Hook access type violation"
);
pub trait IntoHookError {
fn into_hookerror(self) -> HookError;
@ -33,73 +29,3 @@ impl Into<HookError> for (HookErrorKind, Box<Error>) {
}
fn hook_error_type_as_str(e: &HookErrorKind) -> &'static str {
match *e {
HookErrorKind::HookExecutionError => "Hook exec error",
HookErrorKind::AccessTypeViolation => "Hook access type violation",
}
}
impl Display for HookErrorKind {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
try!(write!(fmt, "{}", hook_error_type_as_str(self)));
Ok(())
}
}
/**
* Error type
*/
#[derive(Debug)]
pub struct HookError {
err_type: HookErrorKind,
cause: Option<Box<Error>>,
}
impl HookError {
/**
* Build a new HookError from an HookErrorKind, optionally with cause
*/
pub fn new(errtype: HookErrorKind, cause: Option<Box<Error>>)
-> HookError
{
HookError {
err_type: errtype,
cause: cause,
}
}
/**
* Get the error type of this HookError
*/
pub fn err_type(&self) -> HookErrorKind {
self.err_type
}
}
impl Display for HookError {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
try!(write!(fmt, "[{}]", hook_error_type_as_str(&self.err_type)));
Ok(())
}
}
impl Error for HookError {
fn description(&self) -> &str {
hook_error_type_as_str(&self.err_type)
}
fn cause(&self) -> Option<&Error> {
self.cause.as_ref().map(|e| &**e)
}
}

View File

@ -24,6 +24,8 @@ extern crate semver;
extern crate crossbeam;
extern crate walkdir;
#[macro_use] extern crate libimagerror;
pub mod storeid;
pub mod error;
pub mod hook;