Merge pull request #422 from matthiasbeyer/libimagerror/generate-module
Libimagerror/generate module
This commit is contained in:
commit
6fac67b910
13 changed files with 166 additions and 93 deletions
|
@ -1,9 +1,10 @@
|
||||||
use std::error::Error;
|
generate_error_module!(
|
||||||
use std::fmt::Error as FmtError;
|
|
||||||
use std::fmt::{Display, Formatter};
|
|
||||||
|
|
||||||
generate_error_types!(StoreError, StoreErrorKind,
|
generate_error_types!(StoreError, StoreErrorKind,
|
||||||
BackendError => "Backend Error",
|
BackendError => "Backend Error",
|
||||||
NoCommandlineCall => "No commandline call"
|
NoCommandlineCall => "No commandline call"
|
||||||
);
|
);
|
||||||
|
);
|
||||||
|
|
||||||
|
pub use self::error::StoreError;
|
||||||
|
pub use self::error::StoreErrorKind;
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
use std::error::Error;
|
generate_error_module!(
|
||||||
use std::fmt::Error as FmtError;
|
|
||||||
use std::fmt::{Display, Formatter};
|
|
||||||
|
|
||||||
generate_error_types!(ViewError, ViewErrorKind,
|
generate_error_types!(ViewError, ViewErrorKind,
|
||||||
StoreError => "Store error",
|
StoreError => "Store error",
|
||||||
NoVersion => "No version specified",
|
NoVersion => "No version specified",
|
||||||
PatternError => "Error in Pattern",
|
PatternError => "Error in Pattern",
|
||||||
GlobBuildError => "Could not build glob() Argument"
|
GlobBuildError => "Could not build glob() Argument"
|
||||||
);
|
);
|
||||||
|
);
|
||||||
|
|
||||||
|
pub use self::error::ViewError;
|
||||||
|
pub use self::error::ViewErrorKind;
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
use std::error::Error;
|
generate_error_module!(
|
||||||
use std::fmt::Error as FmtError;
|
|
||||||
use std::fmt::{Display, Formatter};
|
|
||||||
|
|
||||||
generate_error_types!(CounterError, CounterErrorKind,
|
generate_error_types!(CounterError, CounterErrorKind,
|
||||||
StoreReadError => "Store read error",
|
StoreReadError => "Store read error",
|
||||||
StoreWriteError => "Store write error",
|
StoreWriteError => "Store write error",
|
||||||
HeaderTypeError => "Header type error",
|
HeaderTypeError => "Header type error",
|
||||||
HeaderFieldMissingError => "Header field missing error"
|
HeaderFieldMissingError => "Header field missing error"
|
||||||
);
|
);
|
||||||
|
);
|
||||||
|
|
||||||
|
pub use self::error::CounterError;
|
||||||
|
pub use self::error::CounterErrorKind;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
use std::error::Error;
|
generate_error_module!(
|
||||||
use std::fmt::Error as FmtError;
|
|
||||||
use std::fmt::{Display, Formatter};
|
|
||||||
|
|
||||||
generate_error_types!(LinkError, LinkErrorKind,
|
generate_error_types!(LinkError, LinkErrorKind,
|
||||||
EntryHeaderReadError => "Error while reading an entry header",
|
EntryHeaderReadError => "Error while reading an entry header",
|
||||||
EntryHeaderWriteError => "Error while writing an entry header",
|
EntryHeaderWriteError => "Error while writing an entry header",
|
||||||
|
@ -12,4 +9,8 @@ generate_error_types!(LinkError, LinkErrorKind,
|
||||||
StoreReadError => "Store read error",
|
StoreReadError => "Store read error",
|
||||||
StoreWriteError => "Store write error"
|
StoreWriteError => "Store write error"
|
||||||
);
|
);
|
||||||
|
);
|
||||||
|
|
||||||
|
pub use self::error::LinkError;
|
||||||
|
pub use self::error::LinkErrorKind;
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
use std::error::Error;
|
generate_error_module!(
|
||||||
use std::fmt::Error as FmtError;
|
|
||||||
use std::fmt::{Display, Formatter};
|
|
||||||
|
|
||||||
generate_error_types!(ListError, ListErrorKind,
|
generate_error_types!(ListError, ListErrorKind,
|
||||||
FormatError => "FormatError",
|
FormatError => "FormatError",
|
||||||
EntryError => "EntryError",
|
EntryError => "EntryError",
|
||||||
IterationError => "IterationError",
|
IterationError => "IterationError",
|
||||||
CLIError => "No CLI subcommand for listing entries"
|
CLIError => "No CLI subcommand for listing entries"
|
||||||
);
|
);
|
||||||
|
);
|
||||||
|
|
||||||
|
pub use self::error::ListError;
|
||||||
|
pub use self::error::ListErrorKind;
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
use std::error::Error;
|
generate_error_module!(
|
||||||
use std::fmt::Error as FmtError;
|
|
||||||
use std::fmt::{Display, Formatter};
|
|
||||||
|
|
||||||
generate_error_types!(TagError, TagErrorKind,
|
generate_error_types!(TagError, TagErrorKind,
|
||||||
TagTypeError => "Entry Header Tag Type wrong",
|
TagTypeError => "Entry Header Tag Type wrong",
|
||||||
HeaderReadError => "Error while reading entry header",
|
HeaderReadError => "Error while reading entry header",
|
||||||
HeaderWriteError => "Error while writing entry header",
|
HeaderWriteError => "Error while writing entry header",
|
||||||
NotATag => "String is not a tag"
|
NotATag => "String is not a tag"
|
||||||
);
|
);
|
||||||
|
);
|
||||||
|
|
||||||
|
pub use self::error::TagError;
|
||||||
|
pub use self::error::TagErrorKind;
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
use std::error::Error;
|
generate_error_module!(
|
||||||
use std::fmt::Error as FmtError;
|
|
||||||
use std::fmt::{Display, Formatter};
|
|
||||||
|
|
||||||
generate_error_types!(ViewError, ViewErrorKind,
|
generate_error_types!(ViewError, ViewErrorKind,
|
||||||
Unknown => "Unknown view error"
|
Unknown => "Unknown view error"
|
||||||
);
|
);
|
||||||
|
);
|
||||||
|
|
||||||
|
pub use self::error::ViewError;
|
||||||
|
pub use self::error::ViewErrorKind;
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,22 @@
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! generate_error_imports {
|
||||||
|
() => {
|
||||||
|
use std::error::Error;
|
||||||
|
use std::fmt::Error as FmtError;
|
||||||
|
use std::fmt::{Display, Formatter};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! generate_error_module {
|
||||||
|
( $exprs:item ) => {
|
||||||
|
pub mod error {
|
||||||
|
generate_error_imports!();
|
||||||
|
$exprs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! generate_error_types {
|
macro_rules! generate_error_types {
|
||||||
(
|
(
|
||||||
|
@ -71,16 +90,17 @@ macro_rules! generate_error_types {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use std::error::Error;
|
|
||||||
use std::fmt::Error as FmtError;
|
|
||||||
use std::fmt::{Display, Formatter};
|
|
||||||
|
|
||||||
|
generate_error_module!(
|
||||||
generate_error_types!(TestError, TestErrorKind,
|
generate_error_types!(TestError, TestErrorKind,
|
||||||
TestErrorKindA => "testerrorkind a",
|
TestErrorKindA => "testerrorkind a",
|
||||||
TestErrorKindB => "testerrorkind B");
|
TestErrorKindB => "testerrorkind B");
|
||||||
|
);
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_a() {
|
fn test_a() {
|
||||||
|
use self::error::{TestError, TestErrorKind};
|
||||||
|
|
||||||
let kind = TestErrorKind::TestErrorKindA;
|
let kind = TestErrorKind::TestErrorKindA;
|
||||||
assert_eq!(String::from("testerrorkind a"), format!("{}", kind));
|
assert_eq!(String::from("testerrorkind a"), format!("{}", kind));
|
||||||
|
|
||||||
|
@ -90,6 +110,8 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_b() {
|
fn test_b() {
|
||||||
|
use self::error::{TestError, TestErrorKind};
|
||||||
|
|
||||||
let kind = TestErrorKind::TestErrorKindB;
|
let kind = TestErrorKind::TestErrorKindB;
|
||||||
assert_eq!(String::from("testerrorkind B"), format!("{}", kind));
|
assert_eq!(String::from("testerrorkind B"), format!("{}", kind));
|
||||||
|
|
||||||
|
@ -100,6 +122,55 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_ab() {
|
fn test_ab() {
|
||||||
|
use std::error::Error;
|
||||||
|
use self::error::{TestError, TestErrorKind};
|
||||||
|
|
||||||
|
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()));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod anothererrormod {
|
||||||
|
generate_error_imports!();
|
||||||
|
generate_error_types!(TestError, TestErrorKind,
|
||||||
|
TestErrorKindA => "testerrorkind a",
|
||||||
|
TestErrorKindB => "testerrorkind B");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_other_a() {
|
||||||
|
use self::anothererrormod::{TestError, TestErrorKind};
|
||||||
|
|
||||||
|
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_other_b() {
|
||||||
|
use self::anothererrormod::{TestError, TestErrorKind};
|
||||||
|
|
||||||
|
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_other_ab() {
|
||||||
|
use std::error::Error;
|
||||||
|
use self::anothererrormod::{TestError, TestErrorKind};
|
||||||
|
|
||||||
let kinda = TestErrorKind::TestErrorKindA;
|
let kinda = TestErrorKind::TestErrorKindA;
|
||||||
let kindb = TestErrorKind::TestErrorKindB;
|
let kindb = TestErrorKind::TestErrorKindB;
|
||||||
assert_eq!(String::from("testerrorkind a"), format!("{}", kinda));
|
assert_eq!(String::from("testerrorkind a"), format!("{}", kinda));
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
use std::error::Error;
|
generate_error_module!(
|
||||||
use std::fmt::Error as FmtError;
|
|
||||||
use std::fmt::{Display, Formatter};
|
|
||||||
|
|
||||||
generate_error_types!(InteractionError, InteractionErrorKind,
|
generate_error_types!(InteractionError, InteractionErrorKind,
|
||||||
Unknown => "Unknown Error"
|
Unknown => "Unknown Error"
|
||||||
);
|
);
|
||||||
|
);
|
||||||
|
|
||||||
|
pub use self::error::InteractionError;
|
||||||
|
pub use self::error::InteractionErrorKind;
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
use std::error::Error;
|
generate_error_module!(
|
||||||
use std::fmt::Error as FmtError;
|
|
||||||
use std::fmt::{Display, Formatter};
|
|
||||||
|
|
||||||
generate_error_types!(NoteError, NoteErrorKind,
|
generate_error_types!(NoteError, NoteErrorKind,
|
||||||
StoreWriteError => "Error writing store",
|
StoreWriteError => "Error writing store",
|
||||||
StoreReadError => "Error reading store",
|
StoreReadError => "Error reading store",
|
||||||
HeaderTypeError => "Header type error",
|
HeaderTypeError => "Header type error",
|
||||||
NoteToEntryConversion => "Error converting Note instance to Entry instance"
|
NoteToEntryConversion => "Error converting Note instance to Entry instance"
|
||||||
);
|
);
|
||||||
|
);
|
||||||
|
|
||||||
|
pub use self::error::NoteError;
|
||||||
|
pub use self::error::NoteErrorKind;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
use std::error::Error;
|
generate_error_imports!();
|
||||||
use std::fmt::Display;
|
|
||||||
use std::fmt::Formatter;
|
|
||||||
use std::fmt::Error as FmtError;
|
|
||||||
use std::io::Error as IOError;
|
use std::io::Error as IOError;
|
||||||
|
|
||||||
generate_error_types!(RuntimeError, RuntimeErrorKind,
|
generate_error_types!(RuntimeError, RuntimeErrorKind,
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
use std::error::Error;
|
generate_error_imports!();
|
||||||
use std::fmt::Error as FmtError;
|
|
||||||
use std::fmt::{Display, Formatter};
|
|
||||||
use std::convert::From;
|
use std::convert::From;
|
||||||
|
|
||||||
generate_error_types!(StoreError, StoreErrorKind,
|
generate_error_types!(StoreError, StoreErrorKind,
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
use std::error::Error;
|
generate_error_imports!();
|
||||||
use std::fmt::Error as FmtError;
|
|
||||||
use std::fmt::{Display, Formatter};
|
|
||||||
use std::convert::Into;
|
use std::convert::Into;
|
||||||
|
|
||||||
generate_error_types!(HookError, HookErrorKind,
|
generate_error_types!(HookError, HookErrorKind,
|
||||||
|
|
Loading…
Reference in a new issue