Rewrite macros to do error-chain behind the scenes

This commit is contained in:
Matthias Beyer 2017-08-29 14:15:05 +02:00
parent 279afd1972
commit e77d353c52
26 changed files with 1152 additions and 621 deletions

View file

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

View file

@ -16,3 +16,4 @@ homepage = "http://imag-pim.org"
[dependencies]
log = "0.3"
ansi_term = "0.9"
error-chain = "0.10"

View file

@ -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 ),*
error_chain! {
types {
$name, $kindname, ResultExt, Result;
}
impl Display for $kindname {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
let s = match *self {
$( $kindname::$kind => $string ),*
};
try!(write!(fmt, "{}", s));
Ok(())
links {
// None
}
foreign_links {
// None
}
impl IntoError for $kindname {
type Target = $name;
fn into_error(self) -> Self::Target {
$name::new(self, None)
errors {
$(
$kind {
description($string)
display($string)
}
fn into_error_with_cause(self, cause: Box<Error>) -> Self::Target {
$name::new(self, Some(cause))
}
}
#[derive(Debug)]
pub struct $name {
err_type: $kindname,
cause: Option<Box<Error>>,
custom_data: Option<$customMemberTypeName>,
}
impl $name {
pub fn new(errtype: $kindname, cause: Option<Box<Error>>) -> $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)
}
}
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<T> {
fn map_err_into(self, error_kind: $kindname) -> Result<T, $name>;
pub trait MapErrInto<T, E: Error> {
fn map_err_into(self, error_kind: $kindname) -> ::std::result::Result<T, E>;
}
impl<T, E: Error + 'static> MapErrInto<T> for Result<T, E> {
impl<T, E: Error> MapErrInto<T, E: Error> for Result<T, E> {
fn map_err_into(self, error_kind: $kindname) -> Result<T, $name> {
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<T, E> {
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<T> {
fn ok_or_errkind(self, kind: $kindname) -> Result<T, $name>;
fn ok_or_errkind(self, kind: $kindname) -> Result<T>;
}
impl<T> OkOrErr<T> for Option<T> {
fn ok_or_errkind(self, kind: $kindname) -> Result<T, $name> {
self.ok_or(kind.into_error())
fn ok_or_errkind(self, kind: $kindname) -> Result<T> {
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()));
}
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<i32> = None;
match something.ok_or_errkind(TestErrorKind::TestErrorKindA) {

View file

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

View file

@ -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<T> = RResult<T, ConfigError>;
/// `Configuration` object
///
/// Holds all config variables which are globally available plus the configuration object from the

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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"
);
error_chain! {
types {
DatePathCompilerError, DatePathCompilerErrorKind, ResultExt, Result;
}
pub use self::error::DatePathCompilerError;
pub use self::error::DatePathCompilerErrorKind;
pub use self::error::MapErrInto;
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;

View file

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

View file

@ -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;
}
errors {
EndDateTimeBeforeStartDateTime {
description("End datetime is before start datetime")
display("End datetime is before start datetime")
}
}
}
pub use self::error::DateTimeRangeError;
pub use self::error::DateTimeRangeErrorKind;
pub use self::error::MapErrInto;
}
/// Result type for range module
pub mod result {
use std::result::Result as RResult;
use super::error::DateTimeRangeError;
pub type Result<T> = RResult<T, DateTimeRangeError>;
}
use chrono::naive::NaiveDateTime;
use libimagerror::into::IntoError;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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