diff options
author | boastful-squirrel <boastful.squirrel@gmail.com> | 2019-04-27 21:36:49 +0000 |
---|---|---|
committer | boastful-squirrel <boastful.squirrel@gmail.com> | 2019-04-27 21:36:49 +0000 |
commit | 0dd17374c0bb4b94642ed48226d1d55dd2219a02 (patch) | |
tree | 6a794e8f474c1f1870daf5e0cdce7b876ffda12f /src/errors.rs | |
parent | Fixed test + fixed clippy warning (diff) | |
parent | Merge pull request #88 from KSXGitHub/combine-contextual-error (diff) | |
download | miniserve-0dd17374c0bb4b94642ed48226d1d55dd2219a02.tar.gz miniserve-0dd17374c0bb4b94642ed48226d1d55dd2219a02.zip |
Merge branch 'master' into themed-errors
Diffstat (limited to 'src/errors.rs')
-rw-r--r-- | src/errors.rs | 63 |
1 files changed, 5 insertions, 58 deletions
diff --git a/src/errors.rs b/src/errors.rs index bf45b73..8264de0 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,8 +1,7 @@ -use failure::{Backtrace, Context, Fail}; -use std::fmt::{self, Debug, Display}; +use failure::Fail; #[derive(Debug, Fail)] -pub enum ContextualErrorKind { +pub enum ContextualError { /// Fully customized errors, not inheriting from any error #[fail(display = "{}", _0)] CustomError(String), @@ -33,10 +32,7 @@ pub enum ContextualErrorKind { InvalidAuthFormat, /// This error might occure if the hash method is neither sha256 nor sha512 - #[fail( - display = "Invalid hashing method {}. Expected sha256 or sha512", - _0 - )] + #[fail(display = "Invalid hashing method {}. Expected sha256 or sha512", _0)] InvalidHashMethod(String), /// This error might occur if the HTTP auth hash password is not a valid hex code @@ -80,58 +76,9 @@ pub fn log_error_chain(description: String) { } } -/// Based on https://boats.gitlab.io/failure/error-errorkind.html -pub struct ContextualError { - inner: Context<ContextualErrorKind>, -} - -impl ContextualError { - pub fn new(kind: ContextualErrorKind) -> ContextualError { - ContextualError { - inner: Context::new(kind), - } - } -} - -impl Fail for ContextualError { - fn cause(&self) -> Option<&Fail> { - self.inner.cause() - } - - fn backtrace(&self) -> Option<&Backtrace> { - self.inner.backtrace() - } -} - -impl Display for ContextualError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - Display::fmt(&self.inner, f) - } -} - -impl Debug for ContextualError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - Debug::fmt(&self.inner, f) - } -} - -impl From<Context<ContextualErrorKind>> for ContextualError { - fn from(inner: Context<ContextualErrorKind>) -> ContextualError { - ContextualError { inner } - } -} - -impl From<ContextualErrorKind> for ContextualError { - fn from(kind: ContextualErrorKind) -> ContextualError { - ContextualError { - inner: Context::new(kind), - } - } -} - -/// This allows to create CustomErrors more simply +/// This makes creating CustomErrors easier impl From<String> for ContextualError { fn from(msg: String) -> ContextualError { - ContextualError::new(ContextualErrorKind::CustomError(msg)) + ContextualError::CustomError(msg) } } |