diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2016-05-15 00:34:51 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2016-09-07 22:05:12 +0200 |
commit | 8f8568a03ae9fff82e1147552cc03f4b737c30f4 (patch) | |
tree | 318df38770be8ca8c98509ef318a81802334097d /libimagstorestdhook/src/vcs/git/error.rs | |
parent | 07a3a3226532514a1d05b06404b67ed3fa43c64c (diff) |
Add error module setup
Diffstat (limited to 'libimagstorestdhook/src/vcs/git/error.rs')
-rw-r--r-- | libimagstorestdhook/src/vcs/git/error.rs | 87 |
1 files changed, 8 insertions, 79 deletions
diff --git a/libimagstorestdhook/src/vcs/git/error.rs b/libimagstorestdhook/src/vcs/git/error.rs index ca8d7937..fea5b793 100644 --- a/libimagstorestdhook/src/vcs/git/error.rs +++ b/libimagstorestdhook/src/vcs/git/error.rs @@ -1,80 +1,9 @@ -use std::error::Error; -use std::fmt::Error as FmtError; -use std::clone::Clone; -use std::fmt::{Display, Formatter}; - -/** - * Kind of error - */ -#[derive(Clone, Copy, Debug, PartialEq)] -pub enum GitHookErrorKind { -} - -fn githook_error_type_as_str(e: &GitHookErrorKind) -> &'static str { - match *e { - _ => "", - } -} - -impl Display for GitHookErrorKind { - - fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> { - try!(write!(fmt, "{}", githook_error_type_as_str(self))); - Ok(()) - } - -} - -/** - * Store error type - */ -#[derive(Debug)] -pub struct GitHookError { - err_type: GitHookErrorKind, - cause: Option<Box<Error>>, -} - -impl GitHookError { - - /** - * Build a new GitHookError from an GitHookErrorKind, optionally with cause - */ - pub fn new(errtype: GitHookErrorKind, cause: Option<Box<Error>>) - -> GitHookError - { - GitHookError { - err_type: errtype, - cause: cause, - } - } - - /** - * Get the error type of this GitHookError - */ - pub fn err_type(&self) -> GitHookErrorKind { - self.err_type.clone() - } - -} - -impl Display for GitHookError { - - fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> { - try!(write!(fmt, "[{}]", githook_error_type_as_str(&self.err_type.clone()))); - Ok(()) - } - -} - -impl Error for GitHookError { - - fn description(&self) -> &str { - githook_error_type_as_str(&self.err_type.clone()) - } - - fn cause(&self) -> Option<&Error> { - self.cause.as_ref().map(|e| &**e) - } - -} +generate_error_module!( + generate_error_types!(GitHookError, GitHookErrorKind, + MkRepo => "Repository creation error" + ); +); + +pub use self::error::GitHookError; +pub use self::error::GitHookErrorKind; |