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;
|
generate_error_types!(StoreError, StoreErrorKind,
|
||||||
use std::fmt::{Display, Formatter};
|
BackendError => "Backend Error",
|
||||||
|
NoCommandlineCall => "No commandline call"
|
||||||
generate_error_types!(StoreError, StoreErrorKind,
|
);
|
||||||
BackendError => "Backend Error",
|
|
||||||
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;
|
generate_error_types!(ViewError, ViewErrorKind,
|
||||||
use std::fmt::{Display, Formatter};
|
StoreError => "Store error",
|
||||||
|
NoVersion => "No version specified",
|
||||||
generate_error_types!(ViewError, ViewErrorKind,
|
PatternError => "Error in Pattern",
|
||||||
StoreError => "Store error",
|
GlobBuildError => "Could not build glob() Argument"
|
||||||
NoVersion => "No version specified",
|
);
|
||||||
PatternError => "Error in Pattern",
|
|
||||||
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;
|
generate_error_types!(CounterError, CounterErrorKind,
|
||||||
use std::fmt::{Display, Formatter};
|
StoreReadError => "Store read error",
|
||||||
|
StoreWriteError => "Store write error",
|
||||||
generate_error_types!(CounterError, CounterErrorKind,
|
HeaderTypeError => "Header type error",
|
||||||
StoreReadError => "Store read error",
|
HeaderFieldMissingError => "Header field missing error"
|
||||||
StoreWriteError => "Store write error",
|
);
|
||||||
HeaderTypeError => "Header type error",
|
|
||||||
HeaderFieldMissingError => "Header field missing error"
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
pub use self::error::CounterError;
|
||||||
|
pub use self::error::CounterErrorKind;
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
use std::error::Error;
|
generate_error_module!(
|
||||||
use std::fmt::Error as FmtError;
|
generate_error_types!(LinkError, LinkErrorKind,
|
||||||
use std::fmt::{Display, Formatter};
|
EntryHeaderReadError => "Error while reading an entry header",
|
||||||
|
EntryHeaderWriteError => "Error while writing an entry header",
|
||||||
generate_error_types!(LinkError, LinkErrorKind,
|
ExistingLinkTypeWrong => "Existing link entry has wrong type",
|
||||||
EntryHeaderReadError => "Error while reading an entry header",
|
LinkTargetDoesNotExist => "Link target does not exist in the store",
|
||||||
EntryHeaderWriteError => "Error while writing an entry header",
|
InternalConversionError => "Error while converting values internally",
|
||||||
ExistingLinkTypeWrong => "Existing link entry has wrong type",
|
InvalidUri => "URI is not valid",
|
||||||
LinkTargetDoesNotExist => "Link target does not exist in the store",
|
StoreReadError => "Store read error",
|
||||||
InternalConversionError => "Error while converting values internally",
|
StoreWriteError => "Store write error"
|
||||||
InvalidUri => "URI is not valid",
|
);
|
||||||
StoreReadError => "Store read 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;
|
generate_error_types!(ListError, ListErrorKind,
|
||||||
use std::fmt::{Display, Formatter};
|
FormatError => "FormatError",
|
||||||
|
EntryError => "EntryError",
|
||||||
generate_error_types!(ListError, ListErrorKind,
|
IterationError => "IterationError",
|
||||||
FormatError => "FormatError",
|
CLIError => "No CLI subcommand for listing entries"
|
||||||
EntryError => "EntryError",
|
);
|
||||||
IterationError => "IterationError",
|
|
||||||
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;
|
generate_error_types!(TagError, TagErrorKind,
|
||||||
use std::fmt::{Display, Formatter};
|
TagTypeError => "Entry Header Tag Type wrong",
|
||||||
|
HeaderReadError => "Error while reading entry header",
|
||||||
generate_error_types!(TagError, TagErrorKind,
|
HeaderWriteError => "Error while writing entry header",
|
||||||
TagTypeError => "Entry Header Tag Type wrong",
|
NotATag => "String is not a tag"
|
||||||
HeaderReadError => "Error while reading entry header",
|
);
|
||||||
HeaderWriteError => "Error while writing entry header",
|
|
||||||
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;
|
generate_error_types!(ViewError, ViewErrorKind,
|
||||||
use std::fmt::{Display, Formatter};
|
Unknown => "Unknown view error"
|
||||||
|
);
|
||||||
generate_error_types!(ViewError, ViewErrorKind,
|
|
||||||
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_types!(TestError, TestErrorKind,
|
generate_error_module!(
|
||||||
TestErrorKindA => "testerrorkind a",
|
generate_error_types!(TestError, TestErrorKind,
|
||||||
TestErrorKindB => "testerrorkind B");
|
TestErrorKindA => "testerrorkind a",
|
||||||
|
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;
|
generate_error_types!(InteractionError, InteractionErrorKind,
|
||||||
use std::fmt::{Display, Formatter};
|
Unknown => "Unknown Error"
|
||||||
|
);
|
||||||
generate_error_types!(InteractionError, InteractionErrorKind,
|
|
||||||
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;
|
generate_error_types!(NoteError, NoteErrorKind,
|
||||||
use std::fmt::{Display, Formatter};
|
StoreWriteError => "Error writing store",
|
||||||
|
StoreReadError => "Error reading store",
|
||||||
generate_error_types!(NoteError, NoteErrorKind,
|
HeaderTypeError => "Header type error",
|
||||||
StoreWriteError => "Error writing store",
|
NoteToEntryConversion => "Error converting Note instance to Entry instance"
|
||||||
StoreReadError => "Error reading store",
|
);
|
||||||
HeaderTypeError => "Header type error",
|
|
||||||
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