summaryrefslogtreecommitdiffstats
path: root/libimagentrylink
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2016-05-15 16:53:31 +0200
committerMatthias Beyer <mail@beyermatthias.de>2016-05-17 00:26:36 +0200
commit6850146e4286df3529e291eec129b92ebf6a02fb (patch)
treefd9e4ddeda36b777e6b3b2d0758d8f611d300055 /libimagentrylink
parent8602d5855a1b9b661516bc93db69850605b0253e (diff)
libimagentrylink: Replace error code with code generator macro
Diffstat (limited to 'libimagentrylink')
-rw-r--r--libimagentrylink/Cargo.toml3
-rw-r--r--libimagentrylink/src/error.rs95
-rw-r--r--libimagentrylink/src/lib.rs1
3 files changed, 14 insertions, 85 deletions
diff --git a/libimagentrylink/Cargo.toml b/libimagentrylink/Cargo.toml
index 7ac8457e..f14869be 100644
--- a/libimagentrylink/Cargo.toml
+++ b/libimagentrylink/Cargo.toml
@@ -14,3 +14,6 @@ rust-crypto = "0.2.35"
[dependencies.libimagstore]
path = "../libimagstore"
+[dependencies.libimagerror]
+path = "../libimagerror"
+
diff --git a/libimagentrylink/src/error.rs b/libimagentrylink/src/error.rs
index a26e3d58..b587b0ef 100644
--- a/libimagentrylink/src/error.rs
+++ b/libimagentrylink/src/error.rs
@@ -2,89 +2,14 @@ use std::error::Error;
use std::fmt::Error as FmtError;
use std::fmt::{Display, Formatter};
-#[derive(Clone, Copy, Debug, PartialEq)]
-pub enum LinkErrorKind {
- EntryHeaderReadError,
- EntryHeaderWriteError,
- ExistingLinkTypeWrong,
- LinkTargetDoesNotExist,
- InternalConversionError,
- InvalidUri,
- StoreReadError,
- StoreWriteError,
-}
+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",
+ InternalConversionError => "Error while converting values internally",
+ InvalidUri => "URI is not valid",
+ StoreReadError => "Store read error",
+ StoreWriteError => "Store write error"
+);
-fn link_error_type_as_str(e: &LinkErrorKind) -> &'static str {
- match *e {
- LinkErrorKind::EntryHeaderReadError
- => "Error while reading an entry header",
-
- LinkErrorKind::EntryHeaderWriteError
- => "Error while writing an entry header",
-
- LinkErrorKind::ExistingLinkTypeWrong
- => "Existing link entry has wrong type",
-
- LinkErrorKind::LinkTargetDoesNotExist
- => "Link target does not exist in the store",
-
- LinkErrorKind::InternalConversionError
- => "Error while converting values internally",
-
- LinkErrorKind::InvalidUri
- => "URI is not valid",
-
- LinkErrorKind::StoreReadError
- => "Store read error",
-
- LinkErrorKind::StoreWriteError
- => "Store write error",
- }
-}
-
-impl Display for LinkErrorKind {
-
- fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
- try!(write!(fmt, "{}", link_error_type_as_str(self)));
- Ok(())
- }
-
-}
-
-#[derive(Debug)]
-pub struct LinkError {
- kind: LinkErrorKind,
- cause: Option<Box<Error>>,
-}
-
-impl LinkError {
-
- pub fn new(errtype: LinkErrorKind, cause: Option<Box<Error>>) -> LinkError {
- LinkError {
- kind: errtype,
- cause: cause,
- }
- }
-
-}
-
-impl Display for LinkError {
-
- fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
- try!(write!(fmt, "[{}]", link_error_type_as_str(&self.kind)));
- Ok(())
- }
-
-}
-
-impl Error for LinkError {
-
- fn description(&self) -> &str {
- link_error_type_as_str(&self.kind)
- }
-
- fn cause(&self) -> Option<&Error> {
- self.cause.as_ref().map(|e| &**e)
- }
-
-}
diff --git a/libimagentrylink/src/lib.rs b/libimagentrylink/src/lib.rs
index 448bb853..e04b6bf4 100644
--- a/libimagentrylink/src/lib.rs
+++ b/libimagentrylink/src/lib.rs
@@ -20,6 +20,7 @@ extern crate url;
extern crate crypto;
#[macro_use] extern crate libimagstore;
+#[macro_use] extern crate libimagerror;
module_entry_path_mod!("links", "0.1.0");