summaryrefslogtreecommitdiffstats
path: root/libimagtodo
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2016-07-10 16:23:39 +0200
committerMatthias Beyer <mail@beyermatthias.de>2016-07-21 17:14:12 +0200
commitf55f1e627e2ad99c6a558f75ac0841d64eff06c3 (patch)
tree2c2af2f2ff3c683e196325b102741b4eddeea826 /libimagtodo
parent053c5c13e8ddc350fe36f725728ba8ffd5806453 (diff)
Rewrite error module
Diffstat (limited to 'libimagtodo')
-rw-r--r--libimagtodo/src/error.rs76
1 files changed, 11 insertions, 65 deletions
diff --git a/libimagtodo/src/error.rs b/libimagtodo/src/error.rs
index 58fe7758..8aa42410 100644
--- a/libimagtodo/src/error.rs
+++ b/libimagtodo/src/error.rs
@@ -1,66 +1,12 @@
-use std::error::Error;
-use std::clone::Clone;
-use std::fmt::Error as FmtError;
-use std::fmt::{Display, Formatter};
+generate_error_module!(
+ generate_error_types!(TodoError, TodoErrorKind,
+ ConversionError => "Conversion Error",
+ StoreError => "Store Error",
+ ImportError => "Error importing"
+ );
+);
+
+pub use self::error::TodoError;
+pub use self::error::TodoErrorKind;
+pub use self::error::MapErrInto;
-/// Enum of Error Types, as of now we have two:
-/// * ConversionError: for Errors concerning conversion failures from task_hookrs::task::Task to
-/// libimagtodo::task::Task. unused.
-/// * StoreError: For Errors thrown by functions of the Store/structs relates to the Store
-#[derive(Clone, Copy, Debug, PartialEq)]
-pub enum TodoErrorKind {
- ConversionError,
- StoreError,
-}
-
-/// Maps a TodoErrorKind to a String
-fn todo_error_type_as_str(e: &TodoErrorKind) -> &'static str {
- match e {
- &TodoErrorKind::ConversionError => "Conversion Error",
- &TodoErrorKind::StoreError => "Store Error",
- }
-}
-
-impl Display for TodoErrorKind {
- fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
- try!(write!(fmt, "{}", todo_error_type_as_str(self)));
- Ok(())
- }
-}
-
-/// Error struct for the imag-todo module
-#[derive(Debug)]
-pub struct TodoError {
- err_type : TodoErrorKind,
- cause : Option<Box<Error>>,
-}
-
-impl TodoError {
- /// Creates a new TodoError, with TodoErrorKind errtype and an optional cause
- pub fn new(errtype : TodoErrorKind, cause : Option<Box<Error>>) -> TodoError {
- TodoError {
- err_type : errtype,
- cause : cause,
- }
- }
- /// Returns the error type (TodoErrorKind)
- pub fn err_type(&self) -> TodoErrorKind {
- self.err_type.clone()
- }
-}
-
-impl Display for TodoError {
- fn fmt(&self, fmt : &mut Formatter) -> Result<(), FmtError> {
- try!(write!(fmt, "[{}]", todo_error_type_as_str(&self.err_type.clone())));
- Ok(())
- }
-}
-
-impl Error for TodoError {
- fn description(&self) -> &str {
- todo_error_type_as_str(&self.err_type.clone())
- }
- fn cause(&self) -> Option<&Error> {
- self.cause.as_ref().map(|e| &**e)
- }
-}