From e77d353c526ae638085350b364ee876378f4d5f2 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 29 Aug 2017 14:15:05 +0200 Subject: [PATCH] Rewrite macros to do error-chain behind the scenes --- bin/core/imag-store/src/error.rs | 24 +- lib/core/libimagerror/Cargo.toml | 1 + lib/core/libimagerror/src/error_gen.rs | 344 +++-------------- lib/core/libimagerror/src/lib.rs | 3 + lib/core/libimagrt/src/configuration.rs | 42 ++- lib/core/libimagstore/src/error.rs | 349 +++++++++++++----- lib/domain/libimagbookmark/src/error.rs | 42 ++- lib/domain/libimagcounter/src/error.rs | 42 ++- lib/domain/libimagdiary/src/error.rs | 72 +++- lib/domain/libimagmail/src/error.rs | 34 +- lib/domain/libimagnotes/src/error.rs | 36 +- lib/domain/libimagtimetrack/src/error.rs | 43 ++- lib/domain/libimagtodo/src/error.rs | 42 ++- lib/entry/libimagentryannotation/src/error.rs | 47 ++- lib/entry/libimagentrycategory/src/error.rs | 42 ++- .../src/datepath/error.rs | 29 +- lib/entry/libimagentrydatetime/src/error.rs | 64 +++- lib/entry/libimagentrydatetime/src/range.rs | 29 +- lib/entry/libimagentryedit/src/error.rs | 36 +- lib/entry/libimagentrylink/src/error.rs | 84 ++++- lib/entry/libimagentrylist/src/error.rs | 42 ++- lib/entry/libimagentrymarkdown/src/error.rs | 24 +- lib/entry/libimagentryref/src/error.rs | 146 ++++++-- lib/entry/libimagentrytag/src/error.rs | 36 +- lib/entry/libimagentryview/src/error.rs | 42 ++- lib/etc/libimaginteraction/src/error.rs | 78 +++- 26 files changed, 1152 insertions(+), 621 deletions(-) diff --git a/bin/core/imag-store/src/error.rs b/bin/core/imag-store/src/error.rs index bc248ade..d74e4a30 100644 --- a/bin/core/imag-store/src/error.rs +++ b/bin/core/imag-store/src/error.rs @@ -17,12 +17,24 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -generate_error_module!( - generate_error_types!(StoreError, StoreErrorKind, - BackendError => "Backend Error", - NoCommandlineCall => "No commandline call" - ); -); +error_chain! { + types { + StoreError, StoreErrorKind, ResultExt, Result; + } + + errors { + BackendError { + description("Backend Error") + display("Backend Error") + } + + NoCommandlineCall { + description("No commandline call") + display("No commandline call") + } + + } +} pub use self::error::StoreError; pub use self::error::StoreErrorKind; diff --git a/lib/core/libimagerror/Cargo.toml b/lib/core/libimagerror/Cargo.toml index 5f490746..fbfd1bbb 100644 --- a/lib/core/libimagerror/Cargo.toml +++ b/lib/core/libimagerror/Cargo.toml @@ -16,3 +16,4 @@ homepage = "http://imag-pim.org" [dependencies] log = "0.3" ansi_term = "0.9" +error-chain = "0.10" diff --git a/lib/core/libimagerror/src/error_gen.rs b/lib/core/libimagerror/src/error_gen.rs index eb06692c..a03c998f 100644 --- a/lib/core/libimagerror/src/error_gen.rs +++ b/lib/core/libimagerror/src/error_gen.rs @@ -17,138 +17,55 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -#[macro_export] -macro_rules! generate_error_imports { - () => { - use std::error::Error; - use std::fmt::Error as FmtError; - use std::fmt::{Display, Formatter}; - - use $crate::into::IntoError; - } -} - #[macro_export] macro_rules! generate_error_module { ( $exprs:item ) => { pub mod error { - generate_error_imports!(); $exprs } } } #[macro_export] -macro_rules! generate_custom_error_types { +macro_rules! generate_error_types { { $name: ident, $kindname: ident, - $customMemberTypeName: 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(()) - } - - } - - impl IntoError for $kindname { - type Target = $name; - - fn into_error(self) -> Self::Target { - $name::new(self, None) - } - - fn into_error_with_cause(self, cause: Box) -> Self::Target { - $name::new(self, Some(cause)) - } - - } - - #[derive(Debug)] - pub struct $name { - err_type: $kindname, - cause: Option>, - custom_data: Option<$customMemberTypeName>, - } - - impl $name { - - pub fn new(errtype: $kindname, cause: Option>) -> $name { - $name { - err_type: errtype, - cause: cause, - custom_data: None, - } - } - - #[allow(dead_code)] - pub fn err_type(&self) -> $kindname { - self.err_type - } - - #[allow(dead_code)] - pub fn with_custom_data(mut self, custom: $customMemberTypeName) -> $name { - self.custom_data = Some(custom); - self - } - - } - - impl Into<$name> for $kindname { - - fn into(self) -> $name { - $name::new(self, None) - } - - } - - impl Display for $name { - - fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> { - try!(write!(fmt, "[{}]", self.err_type)); - match self.custom_data { - Some(ref c) => write!(fmt, "{}", c), - None => 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) - } - + error_chain! { + types { + $name, $kindname, ResultExt, Result; + } + + links { + // None + } + + foreign_links { + // None + } + + errors { + $( + $kind { + description($string) + display($string) + } + )* + } } + generate_result_helper!($name, $kindname); + generate_option_helper!($name, $kindname); } } #[macro_export] macro_rules! generate_result_helper { - ( - $name: ident, - $kindname: ident - ) => { + { + $name:ident, $kindname:ident + } => { /// Trait to replace /// /// ```ignore @@ -163,15 +80,14 @@ macro_rules! generate_result_helper { /// foo.map_err_into(SomeType::SomeErrorKind) /// ``` /// - pub trait MapErrInto { - fn map_err_into(self, error_kind: $kindname) -> Result; + pub trait MapErrInto { + fn map_err_into(self, error_kind: $kindname) -> ::std::result::Result; } - impl MapErrInto for Result { + impl MapErrInto for Result { - fn map_err_into(self, error_kind: $kindname) -> Result { - self.map_err(Box::new) - .map_err(|e| error_kind.into_error_with_cause(e)) + fn map_err_into(self, error_kind: $kindname) -> ::std::result::Result { + self.chain_err(|| error_kind) } } @@ -180,10 +96,9 @@ macro_rules! generate_result_helper { #[macro_export] macro_rules! generate_option_helper { - ( - $name: ident, - $kindname: ident - ) => { + { + $name:ident, $kindname:ident + } => { /// Trait to replace /// /// ```ignore @@ -196,193 +111,45 @@ macro_rules! generate_option_helper { /// foo.ok_or_errkind(SomeType::SomeErrorKind) /// ``` pub trait OkOrErr { - fn ok_or_errkind(self, kind: $kindname) -> Result; + fn ok_or_errkind(self, kind: $kindname) -> Result; } impl OkOrErr for Option { - fn ok_or_errkind(self, kind: $kindname) -> Result { - self.ok_or(kind.into_error()) + fn ok_or_errkind(self, kind: $kindname) -> Result { + self.ok_or($name::from_kind(kind)) } } } } -#[macro_export] -macro_rules! generate_error_types { - ( - $name: ident, - $kindname: ident, - $($kind:ident => $string:expr),* - ) => { - #[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Copy)] - pub struct SomeNotExistingTypeWithATypeNameNoOneWillEverChoose {} - - impl Display for SomeNotExistingTypeWithATypeNameNoOneWillEverChoose { - fn fmt(&self, _: &mut Formatter) -> Result<(), FmtError> { - Ok(()) - } - } - - generate_custom_error_types!($name, $kindname, - SomeNotExistingTypeWithATypeNameNoOneWillEverChoose, - $($kind => $string),*); - - generate_result_helper!($name, $kindname); - generate_option_helper!($name, $kindname); - } -} - #[cfg(test)] #[allow(dead_code)] mod test { - generate_error_module!( - generate_error_types!(TestError, TestErrorKind, - TestErrorKindA => "testerrorkind a", - TestErrorKindB => "testerrorkind B"); - ); - - #[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Copy)] - pub struct CustomData { - pub test: i32, - pub othr: i64, - } - - impl Display for CustomData { - fn fmt(&self, _: &mut Formatter) -> Result<(), FmtError> { - Ok(()) - } - } - - generate_error_imports!(); - - #[allow(dead_code)] - generate_custom_error_types!(CustomTestError, CustomTestErrorKind, - CustomData, - CustomErrorKindA => "customerrorkind a", - CustomErrorKindB => "customerrorkind B"); - - // Allow dead code here. - // We wrote this to show that custom test types can be implemented. - #[allow(dead_code)] - impl CustomTestError { - pub fn test(&self) -> i32 { - match self.custom_data { - Some(t) => t.test, - None => 0, - } - } - - pub fn bar(&self) -> i64 { - match self.custom_data { - Some(t) => t.othr, - None => 0, - } - } - } - - - #[test] - fn test_a() { - use self::error::{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_b() { - use self::error::{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_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())); - } + generate_error_types!(TestError, TestErrorKind, + TestErrorKindA => "testerrorkind a", + TestErrorKindB => "testerrorkind B"); 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 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())); - } - #[test] fn test_error_kind_mapping() { - use std::io::{Error, ErrorKind}; - use self::error::MapErrInto; - use self::error::TestErrorKind; + use self::MapErrInto; + use self::TestErrorKind; - let err : Result<(), _> = Err(Error::new(ErrorKind::Other, "")); - let err : Result<(), _> = err.map_err_into(TestErrorKind::TestErrorKindA); + let err : Result<()> = Err(TestError::from_kind(TestErrorKind::TestErrorKindB)); + let err : Result<()> = err.map_err_into(TestErrorKind::TestErrorKindA); assert!(err.is_err()); - let err = err.unwrap_err(); - match err.err_type() { + match *err.unwrap_err().kind() { TestErrorKind::TestErrorKindA => assert!(true), _ => assert!(false), } @@ -390,17 +157,16 @@ mod test { #[test] fn test_error_kind_double_mapping() { - use std::io::{Error, ErrorKind}; - use self::error::MapErrInto; - use self::error::TestErrorKind; + use self::TestErrorKind; + use std::error::Error; - let err : Result<(), _> = Err(Error::new(ErrorKind::Other, "")); - let err : Result<(), _> = err.map_err_into(TestErrorKind::TestErrorKindA) + let err : Result<()> = Err(TestError::from_kind(TestErrorKind::TestErrorKindB)); + let err : Result<()> = err.map_err_into(TestErrorKind::TestErrorKindA) .map_err_into(TestErrorKind::TestErrorKindB); assert!(err.is_err()); let err = err.unwrap_err(); - match err.err_type() { + match *err.kind() { TestErrorKind::TestErrorKindB => assert!(true), _ => assert!(false), } @@ -415,8 +181,8 @@ mod test { #[test] fn test_error_option_good() { - use self::error::OkOrErr; - use self::error::TestErrorKind; + use self::OkOrErr; + use self::TestErrorKind; let something = Some(1); match something.ok_or_errkind(TestErrorKind::TestErrorKindA) { @@ -427,8 +193,8 @@ mod test { #[test] fn test_error_option_bad() { - use self::error::OkOrErr; - use self::error::TestErrorKind; + use self::OkOrErr; + use self::TestErrorKind; let something : Option = None; match something.ok_or_errkind(TestErrorKind::TestErrorKindA) { diff --git a/lib/core/libimagerror/src/lib.rs b/lib/core/libimagerror/src/lib.rs index 0ed1e7f3..f9aa7f98 100644 --- a/lib/core/libimagerror/src/lib.rs +++ b/lib/core/libimagerror/src/lib.rs @@ -36,6 +36,9 @@ #[macro_use] extern crate log; extern crate ansi_term; +#[cfg(test)] +#[macro_use] extern crate error_chain; + pub mod into; pub mod error_gen; pub mod trace; diff --git a/lib/core/libimagrt/src/configuration.rs b/lib/core/libimagrt/src/configuration.rs index bc3b52b4..4e064c02 100644 --- a/lib/core/libimagrt/src/configuration.rs +++ b/lib/core/libimagrt/src/configuration.rs @@ -24,24 +24,42 @@ use std::ops::Deref; use toml::Value; use clap::App; -generate_error_module!( - generate_error_types!(ConfigError, ConfigErrorKind, - TOMLParserError => "TOML Parsing error", - NoConfigFileFound => "No config file found", +error_chain! { + types { + ConfigError, ConfigErrorKind, ResultExt, Result; + } - ConfigOverrideError => "Config override error", - ConfigOverrideKeyNotAvailable => "Key not available", - ConfigOverrideTypeNotMatching => "Configuration Type not matching" + errors { + TOMLParserError { + description("TOML Parsing error") + display("TOML Parsing error") + } - ); -); + NoConfigFileFound { + description("No config file found") + display("No config file found") + } + + ConfigOverrideError { + description("Config override error") + display("Config override error") + } + + ConfigOverrideKeyNotAvailable { + description("Key not available") + display("Key not available") + } + + ConfigOverrideTypeNotMatching { + description("Configuration Type not matching") + display("Configuration Type not matching") + } + } +} pub use self::error::{ConfigError, ConfigErrorKind, MapErrInto}; use libimagerror::into::IntoError; -/// Result type of this module. Either `T` or `ConfigError` -pub type Result = RResult; - /// `Configuration` object /// /// Holds all config variables which are globally available plus the configuration object from the diff --git a/lib/core/libimagstore/src/error.rs b/lib/core/libimagstore/src/error.rs index 00e47681..8bba587f 100644 --- a/lib/core/libimagstore/src/error.rs +++ b/lib/core/libimagstore/src/error.rs @@ -17,99 +17,278 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -generate_error_imports!(); -use std::convert::From; - -#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Copy)] -pub struct CustomErrorData {} - -impl Display for CustomErrorData { - fn fmt(&self, _: &mut Formatter) -> Result<(), FmtError> { - Ok(()) // Do nothing here, we don't need to print smth +error_chain! { + types { + StoreError, StoreErrorKind, ResultExt, Result; } -} -generate_custom_error_types!(StoreError, StoreErrorKind, CustomErrorData, - ConfigurationError => "Store Configuration Error", - ConfigTypeError => "Store configuration type error", - ConfigKeyMissingError => "Configuration Key missing", + errors { - VersionError => "Incompatible store versions detected", + ConfigurationError { + description("Store Configuration Error") + display("Store Configuration Error") + } - CreateStoreDirDenied => "Creating store directory implicitely denied", - 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", - FileNotWritten => "File corresponding to ID could not be written to", - FileNotSeeked => "File corresponding to ID could not be seeked", - FileNotRemoved => "File corresponding to ID could not be removed", - FileNotRenamed => "File corresponding to ID could not be renamed", - FileNotCopied => "File could not be copied", - DirNotCreated => "Directory/Directories 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", - StorePathLacksVersion => "The supplied store path has no version part", - GlobError => "glob() error", - EncodingError => "Encoding error", - StorePathError => "Store Path error", - EntryRenameError => "Entry rename error", - StoreIdHandlingError => "StoreId handling error", - StoreIdLocalPartAbsoluteError => "StoreId 'id' part is absolute (starts with '/') which is not allowed", - StoreIdBuildFromFullPathError => "Building StoreId from full file path failed", - StoreIdHasNoBaseError => "StoreId has no 'base' part", + ConfigTypeError { + description("Store configuration type error") + display("Store configuration type error") + } - CreateCallError => "Error when calling create()", - RetrieveCallError => "Error when calling retrieve()", - GetCallError => "Error when calling get()", - GetAllVersionsCallError => "Error when calling get_all_versions()", - RetrieveForModuleCallError => "Error when calling retrieve_for_module()", - UpdateCallError => "Error when calling update()", - RetrieveCopyCallError => "Error when calling retrieve_copy()", - DeleteCallError => "Error when calling delete()", - MoveCallError => "Error when calling move()", - MoveByIdCallError => "Error when calling move_by_id()" -); + ConfigKeyMissingError { + description("Configuration Key missing") + display("Configuration Key missing") + } -generate_result_helper!(StoreError, StoreErrorKind); -generate_option_helper!(StoreError, StoreErrorKind); + VersionError { + description("Incompatible store versions detected") + display("Incompatible store versions detected") + } -generate_custom_error_types!(ParserError, ParserErrorKind, CustomErrorData, - 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" -); + CreateStoreDirDenied { + description("Creating store directory implicitely denied") + display("Creating store directory implicitely denied") + } -impl From for StoreError { - fn from(ps: ParserError) -> StoreError { - StoreError { - err_type: StoreErrorKind::MalformedEntry, - cause: Some(Box::new(ps)), - custom_data: None, - } - } -} - -impl From<::std::io::Error> for StoreError { - fn from(ps: ::std::io::Error) -> StoreError { - StoreError { - err_type: StoreErrorKind::IoError, - cause: Some(Box::new(ps)), - custom_data: None, + FileError { + description("File Error") + display("File Error") + } + + IoError { + description("IO Error") + display("IO Error") + } + + IdLocked { + description("ID locked") + display("ID locked") + } + + IdNotFound { + description("ID not found") + display("ID not found") + } + + OutOfMemory { + description("Out of Memory") + display("Out of Memory") + } + + FileNotFound { + description("File corresponding to ID not found") + display("File corresponding to ID not found") + } + + FileNotCreated { + description("File corresponding to ID could not be created") + display("File corresponding to ID could not be created") + } + + FileNotWritten { + description("File corresponding to ID could not be written to") + display("File corresponding to ID could not be written to") + } + + FileNotSeeked { + description("File corresponding to ID could not be seeked") + display("File corresponding to ID could not be seeked") + } + + FileNotRemoved { + description("File corresponding to ID could not be removed") + display("File corresponding to ID could not be removed") + } + + FileNotRenamed { + description("File corresponding to ID could not be renamed") + display("File corresponding to ID could not be renamed") + } + + FileNotCopied { + description("File could not be copied") + display("File could not be copied") + } + + DirNotCreated { + description("Directory/Directories could not be created") + display("Directory/Directories could not be created") + } + + StorePathExists { + description("Store path exists") + display("Store path exists") + } + + StorePathCreate { + description("Store path create") + display("Store path create") + } + + LockError { + description("Error locking datastructure") + display("Error locking datastructure") + } + + LockPoisoned { + description("The internal Store Lock has been poisoned") + display("The internal Store Lock has been poisoned") + } + + EntryAlreadyBorrowed { + description("Entry is already borrowed") + display("Entry is already borrowed") + } + + EntryAlreadyExists { + description("Entry already exists") + display("Entry already exists") + } + + MalformedEntry { + description("Entry has invalid formatting, missing header") + display("Entry has invalid formatting, missing header") + } + + HeaderPathSyntaxError { + description("Syntax error in accessor string") + display("Syntax error in accessor string") + } + + HeaderPathTypeFailure { + description("Header has wrong type for path") + display("Header has wrong type for path") + } + + HeaderKeyNotFound { + description("Header Key not found") + display("Header Key not found") + } + + HeaderTypeFailure { + description("Header type is wrong") + display("Header type is wrong") + } + + StorePathLacksVersion { + description("The supplied store path has no version part") + display("The supplied store path has no version part") + } + + GlobError { + description("glob() error") + display("glob() error") + } + + EncodingError { + description("Encoding error") + display("Encoding error") + } + + StorePathError { + description("Store Path error") + display("Store Path error") + } + + EntryRenameError { + description("Entry rename error") + display("Entry rename error") + } + + StoreIdHandlingError { + description("StoreId handling error") + display("StoreId handling error") + } + + StoreIdLocalPartAbsoluteError { + description("StoreId 'id' part is absolute (starts with '/') which is not allowed") + display("StoreId 'id' part is absolute (starts with '/') which is not allowed") + } + + StoreIdBuildFromFullPathError { + description("Building StoreId from full file path failed") + display("Building StoreId from full file path failed") + } + + StoreIdHasNoBaseError { + description("StoreId has no 'base' part") + display("StoreId has no 'base' part") + } + + CreateCallError { + description("Error when calling create()") + display("Error when calling create()") + } + + RetrieveCallError { + description("Error when calling retrieve()") + display("Error when calling retrieve()") + } + + GetCallError { + description("Error when calling get()") + display("Error when calling get()") + } + + GetAllVersionsCallError { + description("Error when calling get_all_versions()") + display("Error when calling get_all_versions()") + } + + RetrieveForModuleCallError { + description("Error when calling retrieve_for_module()") + display("Error when calling retrieve_for_module()") + } + + UpdateCallError { + description("Error when calling update()") + display("Error when calling update()") + } + + RetrieveCopyCallError { + description("Error when calling retrieve_copy()") + display("Error when calling retrieve_copy()") + } + + DeleteCallError { + description("Error when calling delete()") + display("Error when calling delete()") + } + + MoveCallError { + description("Error when calling move()") + display("Error when calling move()") + } + + MoveByIdCallError { + description("Error when calling move_by_id()") + display("Error when calling move_by_id()") + } + + // Parser-related errors + + TOMLParserErrors { + description("Several TOML-Parser-Errors") + display("Several TOML-Parser-Errors") + } + + MissingMainSection { + description("Missing main section") + display("Missing main section") + } + + MissingVersionInfo { + description("Missing version information in main section") + display("Missing version information in main section") + } + + NonTableInBaseTable { + description("A non-table was found in the base table") + display("A non-table was found in the base table") + } + + HeaderInconsistency { + description("The header is inconsistent") + display("The header is inconsistent") } } } diff --git a/lib/domain/libimagbookmark/src/error.rs b/lib/domain/libimagbookmark/src/error.rs index 9b52a169..ef01a790 100644 --- a/lib/domain/libimagbookmark/src/error.rs +++ b/lib/domain/libimagbookmark/src/error.rs @@ -17,15 +17,39 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -generate_error_module!( - generate_error_types!(BookmarkError, BookmarkErrorKind, - StoreReadError => "Store read error", - LinkError => "Link error", - LinkParsingError => "Link parsing error", - LinkingError => "Error while linking", - CollectionNotFound => "Link-Collection not found" - ); -); +error_chain! { + types { + BookmarkError, BookmarkErrorKind, ResultExt, Result; + } + + errors { + StoreReadError { + description("Store read error") + display("Store read error") + } + + LinkError { + description("Link error") + display("Link error") + } + + LinkParsingError { + description("Link parsing error") + display("Link parsing error") + } + + LinkingError { + description("Error while linking") + display("Error while linking") + } + + CollectionNotFound { + description("Link-Collection not found") + display("Link-Collection not found") + } + + } +} pub use self::error::BookmarkError; pub use self::error::BookmarkErrorKind; diff --git a/lib/domain/libimagcounter/src/error.rs b/lib/domain/libimagcounter/src/error.rs index c886d901..726eed60 100644 --- a/lib/domain/libimagcounter/src/error.rs +++ b/lib/domain/libimagcounter/src/error.rs @@ -17,15 +17,39 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -generate_error_module!( - generate_error_types!(CounterError, CounterErrorKind, - StoreIdError => "StoreId error", - StoreReadError => "Store read error", - StoreWriteError => "Store write error", - HeaderTypeError => "Header type error", - HeaderFieldMissingError => "Header field missing error" - ); -); +error_chain! { + types { + CounterError, CounterErrorKind, ResultExt, Result; + } + + errors { + StoreIdError { + description("StoreId error") + display("StoreId error") + } + + StoreReadError { + description("Store read error") + display("Store read error") + } + + StoreWriteError { + description("Store write error") + display("Store write error") + } + + HeaderTypeError { + description("Header type error") + display("Header type error") + } + + HeaderFieldMissingError { + description("Header field missing error") + display("Header field missing error") + } + + } +} pub use self::error::CounterError; pub use self::error::CounterErrorKind; diff --git a/lib/domain/libimagdiary/src/error.rs b/lib/domain/libimagdiary/src/error.rs index b5406b12..53b484a7 100644 --- a/lib/domain/libimagdiary/src/error.rs +++ b/lib/domain/libimagdiary/src/error.rs @@ -17,20 +17,64 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -generate_error_module!( - generate_error_types!(DiaryError, DiaryErrorKind, - StoreWriteError => "Error writing store", - StoreReadError => "Error reading store", - CannotFindDiary => "Cannot find diary", - CannotCreateNote => "Cannot create Note object for diary entry", - DiaryEditError => "Cannot edit diary entry", - PathConversionError => "Error while converting paths internally", - EntryNotInDiary => "Entry not in Diary", - IOError => "IO Error", - ViewError => "Error viewing diary entry", - IdParseError => "Error while parsing ID" - ); -); +error_chain! { + types { + DiaryError, DiaryErrorKind, ResultExt, Result; + } + + errors { + StoreWriteError { + description("Error writing store") + display("Error writing store") + } + + StoreReadError { + description("Error reading store") + display("Error reading store") + } + + CannotFindDiary { + description("Cannot find diary") + display("Cannot find diary") + } + + CannotCreateNote { + description("Cannot create Note object for diary entry") + display("Cannot create Note object for diary entry") + } + + DiaryEditError { + description("Cannot edit diary entry") + display("Cannot edit diary entry") + } + + PathConversionError { + description("Error while converting paths internally") + display("Error while converting paths internally") + } + + EntryNotInDiary { + description("Entry not in Diary") + display("Entry not in Diary") + } + + IOError { + description("IO Error") + display("IO Error") + } + + ViewError { + description("Error viewing diary entry") + display("Error viewing diary entry") + } + + IdParseError { + description("Error while parsing ID") + display("Error while parsing ID") + } + + } +} pub use self::error::DiaryError; pub use self::error::DiaryErrorKind; diff --git a/lib/domain/libimagmail/src/error.rs b/lib/domain/libimagmail/src/error.rs index 8c616fba..19a67fd6 100644 --- a/lib/domain/libimagmail/src/error.rs +++ b/lib/domain/libimagmail/src/error.rs @@ -17,17 +17,31 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -generate_error_module!( - generate_error_types!(MailError, MailErrorKind, - RefCreationError => "Error creating a reference to a file/directory", - RefHandlingError => "Error while handling the internal reference object", - MailParsingError => "Error while parsing mail", +error_chain! { + types { + MailError, MailErrorKind, ResultExt, Result; + } - FetchByHashError => "Error fetching mail from Store by hash", - FetchError => "Error fetching mail from Store", - IOError => "IO Error" - ); -); + errors { + RefCreationError { + description("Error creating a reference to a file/directory") + display("Error creating a reference to a file/directory") + } + + FetchByHashError { + description("Error fetching mail from Store by hash") + display("Error fetching mail from Store by hash") + } + FetchError { + description("Error fetching mail from Store") + display("Error fetching mail from Store") + } + IOError { + description("IO Error") + display("IO Error") + } + } +} pub use self::error::MailError; pub use self::error::MailErrorKind; diff --git a/lib/domain/libimagnotes/src/error.rs b/lib/domain/libimagnotes/src/error.rs index 9fd51218..e2793b1c 100644 --- a/lib/domain/libimagnotes/src/error.rs +++ b/lib/domain/libimagnotes/src/error.rs @@ -17,14 +17,34 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -generate_error_module!( - 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" - ); -); +error_chain! { + types { + NoteError, NoteErrorKind, ResultExt, Result; + } + + errors { + StoreWriteError { + description("Error writing store") + display("Error writing store") + } + + StoreReadError { + description("Error reading store") + display("Error reading store") + } + + HeaderTypeError { + description("Header type error") + display("Header type error") + } + + NoteToEntryConversion { + description("Error converting Note instance to Entry instance") + display("Error converting Note instance to Entry instance") + } + + } +} pub use self::error::NoteError; pub use self::error::NoteErrorKind; diff --git a/lib/domain/libimagtimetrack/src/error.rs b/lib/domain/libimagtimetrack/src/error.rs index 3ac4a11a..429d302a 100644 --- a/lib/domain/libimagtimetrack/src/error.rs +++ b/lib/domain/libimagtimetrack/src/error.rs @@ -17,21 +17,40 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -generate_error_module!( - generate_error_types!(TimeTrackError, TimeTrackErrorKind, - StoreReadError => "Store read error", - StoreWriteError => "Store write error", +error_chain! { + types { + TimeTrackError, TimeTrackErrorKind, ResultExt, Result; + } - StoreIdError => "Error while handling StoreId", + errors { + StoreIdError { + description("Error while handling StoreId") + display("Error while handling StoreId") + } - TagFormat => "Tag has invalid format", + TagFormat { + description("Tag has invalid format") + display("Tag has invalid format") + } - HeaderReadError => "Error writing header", - HeaderWriteError => "Error writing header", - HeaderFieldTypeError => "Type error in header", - DateTimeParserError => "Error while parsing DateTime" - ); -); + HeaderReadError { + description("Error writing header") + display("Error writing header") + } + HeaderWriteError { + description("Error writing header") + display("Error writing header") + } + HeaderFieldTypeError { + description("Type error in header") + display("Type error in header") + } + DateTimeParserError { + description("Error while parsing DateTime") + display("Error while parsing DateTime") + } + } +} pub use self::error::TimeTrackError; pub use self::error::TimeTrackErrorKind; diff --git a/lib/domain/libimagtodo/src/error.rs b/lib/domain/libimagtodo/src/error.rs index 621d3249..84a822b2 100644 --- a/lib/domain/libimagtodo/src/error.rs +++ b/lib/domain/libimagtodo/src/error.rs @@ -17,15 +17,39 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -generate_error_module!( - generate_error_types!(TodoError, TodoErrorKind, - ConversionError => "Conversion Error", - StoreError => "Store Error", - StoreIdError => "Store Id handling error", - ImportError => "Error importing", - UTF8Error => "Encountered non-UTF8 characters while reading input" - ); -); +error_chain! { + types { + TodoError, TodoErrorKind, ResultExt, Result; + } + + errors { + ConversionError { + description("Conversion Error"") + display("Conversion Error") + } + + StoreError { + description("Store Error") + display("Store Error") + } + + StoreIdError { + description("Store Id handling error") + display("Store Id handling error") + } + + ImportError { + description("Error importing") + display("Error importing") + } + + UTF8Error { + description("Encountered non-UTF8 characters while reading input) + display("Encountered non-UTF8 characters while reading input) + } + + } +} pub use self::error::TodoError; pub use self::error::TodoErrorKind; diff --git a/lib/entry/libimagentryannotation/src/error.rs b/lib/entry/libimagentryannotation/src/error.rs index 25fc0048..e53c925f 100644 --- a/lib/entry/libimagentryannotation/src/error.rs +++ b/lib/entry/libimagentryannotation/src/error.rs @@ -17,17 +17,44 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -generate_error_module!( - generate_error_types!(AnnotationError, AnnotationErrorKind, - StoreReadError => "Store read error", - StoreWriteError => "Store write error", +error_chain! { + types { + AnnotationError, AnnotationErrorKind, ResultExt, Result; + } - LinkingError => "Error while linking", - HeaderWriteError => "Couldn't write Header for annotation", - HeaderReadError => "Couldn't read Header of Entry", - HeaderTypeError => "Header field has unexpected type" - ); -); + errors { + StoreReadError { + description("Store read error") + display("Store read error") + } + + StoreWriteError { + description("Store write error") + display("Store write error") + } + + LinkingError { + description("Error while linking") + display("Error while linking") + } + + HeaderWriteError { + description("Couldn't write Header for annotation") + display("Couldn't write Header for annotation") + } + + HeaderReadError { + description("Couldn't read Header of Entry") + display("Couldn't read Header of Entry") + } + + HeaderTypeError { + description("Header field has unexpected type") + display("Header field has unexpected type") + } + + } +} pub use self::error::AnnotationError; pub use self::error::AnnotationErrorKind; diff --git a/lib/entry/libimagentrycategory/src/error.rs b/lib/entry/libimagentrycategory/src/error.rs index 72824337..3de6d768 100644 --- a/lib/entry/libimagentrycategory/src/error.rs +++ b/lib/entry/libimagentrycategory/src/error.rs @@ -17,18 +17,38 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -generate_error_module!( - generate_error_types!(CategoryError, CategoryErrorKind, - StoreReadError => "Store Read error", - StoreWriteError => "Store Write error", - StoreIdHandlingError => "StoreId handling error", - HeaderReadError => "Header read error", - HeaderWriteError => "Header write error", - TypeError => "Found wrong type in header", +error_chain! { + types { + CategoryError, CategoryErrorKind, ResultExt, Result; + } - CategoryDoesNotExist => "Category does not exist" - ); -); + errors { + StoreReadError { + description("Store Read error") + display("Store Read error") + } + + StoreWriteError { + description("Store Write error") + display("Store Write error") + } + + StoreIdHandlingError { + description("StoreId handling error") + display("StoreId handling error") + } + + HeaderReadError { + description("Header read error") + display("Header read error") + } + + CategoryDoesNotExist { + description("Category does not exist") + display("Category does not exist") + } + } +} pub use self::error::CategoryError; pub use self::error::CategoryErrorKind; diff --git a/lib/entry/libimagentrydatetime/src/datepath/error.rs b/lib/entry/libimagentrydatetime/src/datepath/error.rs index 1a163208..d0b28665 100644 --- a/lib/entry/libimagentrydatetime/src/datepath/error.rs +++ b/lib/entry/libimagentrydatetime/src/datepath/error.rs @@ -17,14 +17,23 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -/// Error module for the DatePathCompiler type -generate_error_module! { - generate_error_types!(DatePathCompilerError, DatePathCompilerErrorKind, - UnknownDatePathCompilerError => "Unknown DatePathCompiler error", - StoreIdBuildFailed => "Failed building StoreId object" - ); -} -pub use self::error::DatePathCompilerError; -pub use self::error::DatePathCompilerErrorKind; -pub use self::error::MapErrInto; +error_chain! { + types { + DatePathCompilerError, DatePathCompilerErrorKind, ResultExt, Result; + } + errors { + UnknownDatePathCompilerError { + description("Unknown DatePathCompiler error") + display("Unknown DatePathCompiler error") + } + + StoreIdBuildFailed { + description("Failed building StoreId object") + display("Failed building StoreId object") + } + + } +} + +pub use self::error::DatePathCompilerError; diff --git a/lib/entry/libimagentrydatetime/src/error.rs b/lib/entry/libimagentrydatetime/src/error.rs index 0f0166a0..cf434aca 100644 --- a/lib/entry/libimagentrydatetime/src/error.rs +++ b/lib/entry/libimagentrydatetime/src/error.rs @@ -17,21 +17,59 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -generate_error_module!( - generate_error_types!(DateError, DateErrorKind, - DeleteDateError => "Error deleting date", - ReadDateError => "Error reading date", - SetDateError => "Error setting date", - DeleteDateTimeRangeError => "Error deleting date-time range", - ReadDateTimeRangeError => "Error reading date-time range", - SetDateTimeRangeError => "Error setting date-time range", +error_chain! { + types { + DateError, DateErrorKind, ResultExt, Result; + } - DateTimeRangeError => "DateTime Range error", + errors { + DeleteDateError { + description("Error deleting date") + display("Error deleting date") + } - DateHeaderFieldTypeError => "Expected the header field in the entry to have type 'String', but have other type", - DateTimeParsingError => "Error parsing DateTime" - ); -); + ReadDateError { + description("Error reading date") + display("Error reading date") + } + + SetDateError { + description("Error setting date") + display("Error setting date") + } + + DeleteDateTimeRangeError { + description("Error deleting date-time range") + display("Error deleting date-time range") + } + + ReadDateTimeRangeError { + description("Error reading date-time range") + display("Error reading date-time range") + } + + SetDateTimeRangeError { + description("Error setting date-time range") + display("Error setting date-time range") + } + + DateTimeRangeError { + description("DateTime Range error") + display("DateTime Range error") + } + + DateHeaderFieldTypeError { + description("Expected the header field in the entry to have type 'String', but have other type") + display("Expected the header field in the entry to have type 'String', but have other type") + } + + DateTimeParsingError { + description("Error parsing DateTime") + display("Error parsing DateTime") + } + + } +} pub use self::error::DateError; pub use self::error::DateErrorKind; diff --git a/lib/entry/libimagentrydatetime/src/range.rs b/lib/entry/libimagentrydatetime/src/range.rs index 8820b7a3..52c8095a 100644 --- a/lib/entry/libimagentrydatetime/src/range.rs +++ b/lib/entry/libimagentrydatetime/src/range.rs @@ -18,25 +18,22 @@ // /// Error types for range module -pub mod error { - generate_error_module!( - generate_error_types!(DateTimeRangeError, DateTimeRangeErrorKind, - EndDateTimeBeforeStartDateTime => "End datetime is before start datetime" - ); - ); +error_chain! { + types { + DateTimeRangeError, DateTimeRangeErrorKind, ResultExt, Result; + } - pub use self::error::DateTimeRangeError; - pub use self::error::DateTimeRangeErrorKind; - pub use self::error::MapErrInto; + errors { + EndDateTimeBeforeStartDateTime { + description("End datetime is before start datetime") + display("End datetime is before start datetime") + } + } } -/// Result type for range module -pub mod result { - use std::result::Result as RResult; - use super::error::DateTimeRangeError; - - pub type Result = RResult; -} +pub use self::error::DateTimeRangeError; +pub use self::error::DateTimeRangeErrorKind; +pub use self::error::MapErrInto; use chrono::naive::NaiveDateTime; use libimagerror::into::IntoError; diff --git a/lib/entry/libimagentryedit/src/error.rs b/lib/entry/libimagentryedit/src/error.rs index 478d5d2c..fde19983 100644 --- a/lib/entry/libimagentryedit/src/error.rs +++ b/lib/entry/libimagentryedit/src/error.rs @@ -17,14 +17,34 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -generate_error_module!( - generate_error_types!(EditError, EditErrorKind, - IOError => "IO Error", - NoEditor => "No editor set", - ProcessExitFailure => "Process did not exit properly", - InstantiateError => "Instantation error" - ); -); +error_chain! { + types { + EditError, EditErrorKind, ResultExt, Result; + } + + errors { + IOError { + description("IO Error") + display("IO Error") + } + + NoEditor { + description("No editor set") + display("No editor set") + } + + ProcessExitFailure { + description("Process did not exit properly") + display("Process did not exit properly") + } + + InstantiateError { + description("Instantation error") + display("Instantation error") + } + + } +} pub use self::error::EditError; pub use self::error::EditErrorKind; diff --git a/lib/entry/libimagentrylink/src/error.rs b/lib/entry/libimagentrylink/src/error.rs index 10d83f94..5b315149 100644 --- a/lib/entry/libimagentrylink/src/error.rs +++ b/lib/entry/libimagentrylink/src/error.rs @@ -17,22 +17,74 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -generate_error_module!( - 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", - LinkParserError => "Link cannot be parsed", - LinkParserFieldMissingError => "Link cannot be parsed: Field missing", - LinkParserFieldTypeError => "Link cannot be parsed: Field type wrong", - InternalConversionError => "Error while converting values internally", - InvalidUri => "URI is not valid", - StoreReadError => "Store read error", - StoreWriteError => "Store write error", - StoreIdError => "StoreId handling error" - ); -); +error_chain! { + types { + LinkError, LinkErrorKind, ResultExt, Result; + } + + errors { + EntryHeaderReadError { + description("Error while reading an entry header") + display("Error while reading an entry header") + } + + EntryHeaderWriteError { + description("Error while writing an entry header") + display("Error while writing an entry header") + } + + ExistingLinkTypeWrong { + description("Existing link entry has wrong type") + display("Existing link entry has wrong type") + } + + LinkTargetDoesNotExist { + description("Link target does not exist in the store") + display("Link target does not exist in the store") + } + + LinkParserError { + description("Link cannot be parsed") + display("Link cannot be parsed") + } + + LinkParserFieldMissingError { + description("Link cannot be parsed: Field missing") + display("Link cannot be parsed: Field missing") + } + + LinkParserFieldTypeError { + description("Link cannot be parsed: Field type wrong") + display("Link cannot be parsed: Field type wrong") + } + + InternalConversionError { + description("Error while converting values internally") + display("Error while converting values internally") + } + + InvalidUri { + description("URI is not valid") + display("URI is not valid") + } + + StoreReadError { + description("Store read error") + display("Store read error") + } + + StoreWriteError { + description("Store write error") + display("Store write error") + } + + StoreIdError { + description("StoreId handling error") + display("StoreId handling error") + } + + } +} pub use self::error::LinkError; pub use self::error::LinkErrorKind; diff --git a/lib/entry/libimagentrylist/src/error.rs b/lib/entry/libimagentrylist/src/error.rs index 9c3b1ccc..e743c468 100644 --- a/lib/entry/libimagentrylist/src/error.rs +++ b/lib/entry/libimagentrylist/src/error.rs @@ -17,15 +17,39 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -generate_error_module!( - generate_error_types!(ListError, ListErrorKind, - IOError => "IO Error", - FormatError => "FormatError", - EntryError => "EntryError", - IterationError => "IterationError", - CLIError => "No CLI subcommand for listing entries" - ); -); +error_chain! { + types { + ListError, ListErrorKind, ResultExt, Result; + } + + errors { + IOError { + description("IO Error") + display("IO Error") + } + + FormatError { + description("FormatError") + display("FormatError") + } + + EntryError { + description("EntryError") + display("EntryError") + } + + IterationError { + description("IterationError") + display("IterationError") + } + + CLIError { + description("No CLI subcommand for listing entries") + display("No CLI subcommand for listing entries") + } + + } +} pub use self::error::ListError; pub use self::error::ListErrorKind; diff --git a/lib/entry/libimagentrymarkdown/src/error.rs b/lib/entry/libimagentrymarkdown/src/error.rs index 1186d5f3..da099a7d 100644 --- a/lib/entry/libimagentrymarkdown/src/error.rs +++ b/lib/entry/libimagentrymarkdown/src/error.rs @@ -17,12 +17,24 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -generate_error_module!( - generate_error_types!(MarkdownError, MarkdownErrorKind, - MarkdownRenderError => "Markdown render error", - LinkParsingError => "Link parsing error" - ); -); +error_chain! { + types { + MarkdownError, MarkdownErrorKind, ResultExt, Result; + } + + errors { + MarkdownRenderError { + description("Markdown render error") + display("Markdown render error") + } + + LinkParsingError { + description("Link parsing error") + display("Link parsing error") + } + + } +} pub use self::error::MarkdownError; pub use self::error::MarkdownErrorKind; diff --git a/lib/entry/libimagentryref/src/error.rs b/lib/entry/libimagentryref/src/error.rs index 56c1e869..fb413929 100644 --- a/lib/entry/libimagentryref/src/error.rs +++ b/lib/entry/libimagentryref/src/error.rs @@ -17,37 +17,129 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -generate_error_module!( - generate_error_types!(RefError, RefErrorKind, - StoreReadError => "Store read error", - StoreWriteError => "Store write error", - IOError => "IO Error", - UTF8Error => "UTF8 Error", - StoreIdError => "Error with storeid", - HeaderTomlError => "Error while working with TOML Header", - HeaderTypeError => "Header type error", - HeaderFieldMissingError => "Header field missing error", - HeaderFieldWriteError => "Header field cannot be written", - HeaderFieldReadError => "Header field cannot be read", - HeaderFieldAlreadyExistsError => "Header field already exists, cannot override", - PathUTF8Error => "Path cannot be converted because of UTF8 Error", - PathHashingError => "Path cannot be hashed", - PathCanonicalizationError => "Path cannot be canonicalized", +error_chain! { + types { + RefError, RefErrorKind, ResultExt, Result; + } - TypeConversionError => "Couldn't convert types", - RefToDisplayError => "Cannot convert Ref to string to show it to user", + errors { + StoreReadError { + description("Store read error") + display("Store read error") + } - RefNotInStore => "Ref/StoreId does not exist in store", + StoreWriteError { + description("Store write error") + display("Store write error") + } - RefTargetDoesNotExist => "Ref Target does not exist", - RefTargetPermissionError => "Ref Target permissions insufficient for referencing", - RefTargetCannotBeHashed => "Ref Target cannot be hashed (is it a directory?)", - RefTargetFileCannotBeOpened => "Ref Target File cannot be open()ed", - RefTargetCannotReadPermissions => "Ref Target: Cannot read permissions", + IOError { + description("IO Error") + display("IO Error") + } - RefHashingError => "Error while hashing" - ); -); + UTF8Error { + description("UTF8 Error") + display("UTF8 Error") + } + + StoreIdError { + description("Error with storeid") + display("Error with storeid") + } + + HeaderTomlError { + description("Error while working with TOML Header") + display("Error while working with TOML Header") + } + + HeaderTypeError { + description("Header type error") + display("Header type error") + } + + HeaderFieldMissingError { + description("Header field missing error") + display("Header field missing error") + } + + HeaderFieldWriteError { + description("Header field cannot be written") + display("Header field cannot be written") + } + + HeaderFieldReadError { + description("Header field cannot be read") + display("Header field cannot be read") + } + + HeaderFieldAlreadyExistsError { + description("Header field already exists, cannot override") + display("Header field already exists, cannot override") + } + + PathUTF8Error { + description("Path cannot be converted because of UTF8 Error") + display("Path cannot be converted because of UTF8 Error") + } + + PathHashingError { + description("Path cannot be hashed") + display("Path cannot be hashed") + } + + PathCanonicalizationError { + description("Path cannot be canonicalized") + display("Path cannot be canonicalized") + } + + TypeConversionError { + description("Couldn't convert types") + display("Couldn't convert types") + } + + RefToDisplayError { + description("Cannot convert Ref to string to show it to user") + display("Cannot convert Ref to string to show it to user") + } + + RefNotInStore { + description("Ref/StoreId does not exist in store") + display("Ref/StoreId does not exist in store") + } + + RefTargetDoesNotExist { + description("Ref Target does not exist") + display("Ref Target does not exist") + } + + RefTargetPermissionError { + description("Ref Target permissions insufficient for referencing") + display("Ref Target permissions insufficient for referencing") + } + + RefTargetCannotBeHashed { + description("Ref Target cannot be hashed (is it a directory?)") + display("Ref Target cannot be hashed (is it a directory?)") + } + + RefTargetFileCannotBeOpened { + description("Ref Target File cannot be open()ed") + display("Ref Target File cannot be open()ed") + } + + RefTargetCannotReadPermissions { + description("Ref Target: Cannot read permissions") + display("Ref Target: Cannot read permissions") + } + + RefHashingError { + description("Error while hashing") + display("Error while hashing") + } + + } +} pub use self::error::RefError; pub use self::error::RefErrorKind; diff --git a/lib/entry/libimagentrytag/src/error.rs b/lib/entry/libimagentrytag/src/error.rs index 579e3ce8..cde51b1c 100644 --- a/lib/entry/libimagentrytag/src/error.rs +++ b/lib/entry/libimagentrytag/src/error.rs @@ -17,14 +17,34 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -generate_error_module!( - 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" - ); -); +error_chain! { + types { + TagError, TagErrorKind, ResultExt, Result; + } + + errors { + TagTypeError { + description("Entry Header Tag Type wrong") + display("Entry Header Tag Type wrong") + } + + HeaderReadError { + description("Error while reading entry header") + display("Error while reading entry header") + } + + HeaderWriteError { + description("Error while writing entry header") + display("Error while writing entry header") + } + + NotATag { + description("String is not a tag") + display("String is not a tag") + } + + } +} pub use self::error::TagError; pub use self::error::TagErrorKind; diff --git a/lib/entry/libimagentryview/src/error.rs b/lib/entry/libimagentryview/src/error.rs index c471b3f3..5e1c5f11 100644 --- a/lib/entry/libimagentryview/src/error.rs +++ b/lib/entry/libimagentryview/src/error.rs @@ -17,15 +17,39 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -generate_error_module!( - generate_error_types!(ViewError, ViewErrorKind, - Unknown => "Unknown view error", - GlobError => "Error while glob()ing", - PatternError => "Error in glob() pattern", - PatternBuildingError => "Could not build glob() pattern", - ViewError => "Failed to start viewer" - ); -); +error_chain! { + types { + ViewError, ViewErrorKind, ResultExt, Result; + } + + errors { + Unknown { + description("Unknown view error") + display("Unknown view error") + } + + GlobError { + description("Error while glob()ing") + display("Error while glob()ing") + } + + PatternError { + description("Error in glob() pattern") + display("Error in glob() pattern") + } + + PatternBuildingError { + description("Could not build glob() pattern") + display("Could not build glob() pattern") + } + + ViewError { + description("Failed to start viewer") + display("Failed to start viewer") + } + + } +} pub use self::error::ViewError; pub use self::error::ViewErrorKind; diff --git a/lib/etc/libimaginteraction/src/error.rs b/lib/etc/libimaginteraction/src/error.rs index 1a4be7df..b54c54a4 100644 --- a/lib/etc/libimaginteraction/src/error.rs +++ b/lib/etc/libimaginteraction/src/error.rs @@ -17,21 +17,69 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -generate_error_module!( - generate_error_types!(InteractionError, InteractionErrorKind, - Unknown => "Unknown Error", - CLIError => "Error on commandline", - IdMissingError => "Commandline: ID missing", - StoreIdParsingError => "Error while parsing StoreId", - IdSelectingError => "Error while selecting id", - ConfigError => "Configuration error", - ConfigMissingError => "Configuration missing", - ConfigTypeError => "Config Type Error", - NoConfigError => "No configuration", - ReadlineHistoryFileCreationError => "Could not create history file for readline", - ReadlineError => "Readline error" - ); -); +error_chain! { + types { + InteractionError, InteractionErrorKind, ResultExt, Result; + } + + errors { + Unknown { + description("Unknown Error") + display("Unknown Error") + } + + CLIError { + description("Error on commandline") + display("Error on commandline") + } + + IdMissingError { + description("Commandline: ID missing") + display("Commandline: ID missing") + } + + StoreIdParsingError { + description("Error while parsing StoreId") + display("Error while parsing StoreId") + } + + IdSelectingError { + description("Error while selecting id") + display("Error while selecting id") + } + + ConfigError { + description("Configuration error") + display("Configuration error") + } + + ConfigMissingError { + description("Configuration missing") + display("Configuration missing") + } + + ConfigTypeError { + description("Config Type Error") + display("Config Type Error") + } + + NoConfigError { + description("No configuration") + display("No configuration") + } + + ReadlineHistoryFileCreationError { + description("Could not create history file for readline") + display("Could not create history file for readline") + } + + ReadlineError { + description("Readline error") + display("Readline error") + } + + } +} pub use self::error::InteractionError; pub use self::error::InteractionErrorKind;