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] [dependencies.libimagutil]
path = "../libimagutil" path = "../libimagutil"
[dependencies.libimagerror]
path = "../libimagerror"

View file

@ -1,75 +1,9 @@
use std::error::Error; use std::error::Error;
use std::fmt::Error as FmtError; use std::fmt::Error as FmtError;
use std::clone::Clone;
use std::fmt::{Display, Formatter}; use std::fmt::{Display, Formatter};
#[derive(Clone, Copy, Debug, PartialEq)] generate_error_types!(StoreError, StoreErrorKind,
/// Kind of store error BackendError => "Backend Error",
pub enum StoreErrorKind { NoCommandlineCall => "No commandline call"
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)
}
}

View file

@ -22,6 +22,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;
use libimagrt::runtime::Runtime; use libimagrt::runtime::Runtime;
use std::process::exit; use std::process::exit;

View file

@ -21,3 +21,6 @@ path = "../libimagrt"
[dependencies.libimagutil] [dependencies.libimagutil]
path = "../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::Error as FmtError;
use std::fmt::{Display, Formatter}; use std::fmt::{Display, Formatter};
/** generate_error_types!(ViewError, ViewErrorKind,
* Kind of store error StoreError => "Store error",
*/ NoVersion => "No version specified",
#[derive(Clone, Copy, Debug, PartialEq)] PatternError => "Error in Pattern",
pub enum ViewErrorKind { GlobBuildError => "Could not build glob() Argument"
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)
}
}

View file

@ -23,6 +23,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;
use std::result::Result as RResult; use std::result::Result as RResult;
use std::process::exit; use std::process::exit;

View file

@ -11,3 +11,6 @@ semver = "0.2"
[dependencies.libimagstore] [dependencies.libimagstore]
path = "../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::Error as FmtError;
use std::fmt::{Display, Formatter}; use std::fmt::{Display, Formatter};
/** generate_error_types!(CounterError, CounterErrorKind,
* Kind of error StoreReadError => "Store read error",
*/ StoreWriteError => "Store write error",
#[derive(Clone, Copy, Debug, PartialEq)] HeaderTypeError => "Header type error",
pub enum CounterErrorKind { HeaderFieldMissingError => "Header field missing error"
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)
}
}

View file

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

View file

@ -14,3 +14,6 @@ rust-crypto = "0.2.35"
[dependencies.libimagstore] [dependencies.libimagstore]
path = "../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::Error as FmtError;
use std::fmt::{Display, Formatter}; use std::fmt::{Display, Formatter};
#[derive(Clone, Copy, Debug, PartialEq)] generate_error_types!(LinkError, LinkErrorKind,
pub enum LinkErrorKind { EntryHeaderReadError => "Error while reading an entry header",
EntryHeaderReadError, EntryHeaderWriteError => "Error while writing an entry header",
EntryHeaderWriteError, ExistingLinkTypeWrong => "Existing link entry has wrong type",
ExistingLinkTypeWrong, LinkTargetDoesNotExist => "Link target does not exist in the store",
LinkTargetDoesNotExist, InternalConversionError => "Error while converting values internally",
InternalConversionError, InvalidUri => "URI is not valid",
InvalidUri, StoreReadError => "Store read error",
StoreReadError, StoreWriteError => "Store write error"
StoreWriteError, );
}
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; extern crate crypto;
#[macro_use] extern crate libimagstore; #[macro_use] extern crate libimagstore;
#[macro_use] extern crate libimagerror;
module_entry_path_mod!("links", "0.1.0"); module_entry_path_mod!("links", "0.1.0");

View file

@ -11,3 +11,6 @@ toml = "0.1.25"
[dependencies.libimagstore] [dependencies.libimagstore]
path = "../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::Error as FmtError;
use std::fmt::{Display, Formatter}; use std::fmt::{Display, Formatter};
/** generate_error_types!(ListError, ListErrorKind,
* Kind of error FormatError => "FormatError",
*/ EntryError => "EntryError",
#[derive(Clone, Copy, Debug, PartialEq)] IterationError => "IterationError",
pub enum ListErrorKind { CLIError => "No CLI subcommand for listing entries"
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)
}
}

View file

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

View file

@ -13,3 +13,6 @@ itertools = "0.4"
[dependencies.libimagstore] [dependencies.libimagstore]
path = "../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::Error as FmtError;
use std::fmt::{Display, Formatter}; use std::fmt::{Display, Formatter};
#[derive(Clone, Copy, Debug, PartialEq)] generate_error_types!(TagError, TagErrorKind,
pub enum TagErrorKind { TagTypeError => "Entry Header Tag Type wrong",
TagTypeError, HeaderReadError => "Error while reading entry header",
HeaderReadError, HeaderWriteError => "Error while writing entry header",
HeaderWriteError, NotATag => "String is not a tag"
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)
}
}

View file

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

View file

@ -8,3 +8,6 @@ authors = ["Matthias Beyer <mail@beyermatthias.de>"]
[dependencies.libimagstore] [dependencies.libimagstore]
path = "../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::Error as FmtError;
use std::fmt::{Display, Formatter}; use std::fmt::{Display, Formatter};
/** generate_error_types!(ViewError, ViewErrorKind,
* Kind of error Unknown => "Unknown view 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)
}
}

View file

@ -15,6 +15,7 @@
)] )]
extern crate libimagstore; extern crate libimagstore;
#[macro_use] extern crate libimagerror;
pub mod error; pub mod error;
pub mod builtin; 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] [dependencies.libimagutil]
path = "../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::Error as FmtError;
use std::fmt::{Display, Formatter}; use std::fmt::{Display, Formatter};
/** generate_error_types!(InteractionError, InteractionErrorKind,
* Kind of error Unknown => "Unknown 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)
}
}

View file

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

View file

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

View file

@ -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)
}
}

View file

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

View file

@ -21,3 +21,6 @@ path = "../libimagstorestdhook"
[dependencies.libimagutil] [dependencies.libimagutil]
path = "../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::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 {

View file

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

View file

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

View file

@ -1,138 +1,45 @@
use std::error::Error; use std::error::Error;
use std::fmt::Error as FmtError; use std::fmt::Error as FmtError;
use std::fmt::{Debug, Display, Formatter}; use std::fmt::{Display, Formatter};
use std::fmt;
use std::convert::From; use std::convert::From;
/** generate_error_types!(StoreError, StoreErrorKind,
* Kind of store error ConfigurationError => "Store Configuration Error",
*/ FileError => "File Error",
#[derive(Clone, Copy, Debug, PartialEq)] IoError => "IO Error",
pub enum StoreErrorKind { IdLocked => "ID locked",
ConfigurationError, IdNotFound => "ID not found",
FileError, OutOfMemory => "Out of Memory",
IdLocked, FileNotFound => "File corresponding to ID not found",
IdNotFound, FileNotCreated => "File corresponding to ID could not be created",
OutOfMemory, StorePathExists => "Store path exists",
FileNotFound, StorePathCreate => "Store path create",
FileNotCreated, LockError => "Error locking datastructure",
IoError, LockPoisoned => "The internal Store Lock has been poisoned",
StorePathExists, EntryAlreadyBorrowed => "Entry is already borrowed",
StorePathCreate, EntryAlreadyExists => "Entry already exists",
LockError, MalformedEntry => "Entry has invalid formatting, missing header",
LockPoisoned, HeaderPathSyntaxError => "Syntax error in accessor string",
EntryAlreadyBorrowed, HeaderPathTypeFailure => "Header has wrong type for path",
EntryAlreadyExists, HeaderKeyNotFound => "Header Key not found",
MalformedEntry, HeaderTypeFailure => "Header type is wrong",
HeaderPathSyntaxError, HookRegisterError => "Hook register error",
HeaderPathTypeFailure, AspectNameNotFoundError => "Aspect name not found",
HeaderKeyNotFound, HookExecutionError => "Hook execution error",
HeaderTypeFailure, PreHookExecuteError => "Pre-Hook execution error",
HookRegisterError, PostHookExecuteError => "Post-Hook execution error",
AspectNameNotFoundError, StorePathLacksVersion => "The supplied store path has no version part",
HookExecutionError, GlobError => "glob() error",
PreHookExecuteError, EncodingError => "Encoding error"
PostHookExecuteError, );
StorePathLacksVersion,
GlobError,
EncodingError,
// maybe more
}
fn store_error_type_as_str(e: &StoreErrorKind) -> &'static str { generate_error_types!(ParserError, ParserErrorKind,
match *e { TOMLParserErrors => "Several TOML-Parser-Errors",
StoreErrorKind::ConfigurationError => "Store Configuration Error", MissingMainSection => "Missing main section",
StoreErrorKind::FileError | MissingVersionInfo => "Missing version information in main section",
StoreErrorKind::IoError => "File Error", NonTableInBaseTable => "A non-table was found in the base table",
StoreErrorKind::IdLocked => "ID locked", HeaderInconsistency => "The header is inconsistent"
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)
}
}
impl From<ParserError> for StoreError { impl From<ParserError> for StoreError {
fn from(ps: ParserError) -> 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::fmt::{Display, Formatter};
use std::convert::Into; use std::convert::Into;
/** generate_error_types!(HookError, HookErrorKind,
* Kind of error HookExecutionError => "Hook exec error",
*/ AccessTypeViolation => "Hook access type violation"
#[derive(Clone, Copy, Debug)] );
pub enum HookErrorKind {
HookExecutionError,
AccessTypeViolation,
}
pub trait IntoHookError { pub trait IntoHookError {
fn into_hookerror(self) -> HookError; 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 crossbeam;
extern crate walkdir; extern crate walkdir;
#[macro_use] extern crate libimagerror;
pub mod storeid; pub mod storeid;
pub mod error; pub mod error;
pub mod hook; pub mod hook;