aboutsummaryrefslogtreecommitdiffstats
path: root/src/errors.rs
diff options
context:
space:
mode:
authorSven-Hendrik Haase <svenstaro@gmail.com>2019-04-27 19:31:07 +0000
committerGitHub <noreply@github.com>2019-04-27 19:31:07 +0000
commit18fcc8e699897ceca75920722531b79d909f28fc (patch)
tree9e855f3afbbe8237a09c9c364832f8c5aa4e57e8 /src/errors.rs
parentDescribe hashed password feature in README (diff)
parentCombine ContextualError and ContextualErrorKind into one (diff)
downloadminiserve-18fcc8e699897ceca75920722531b79d909f28fc.tar.gz
miniserve-18fcc8e699897ceca75920722531b79d909f28fc.zip
Merge pull request #88 from KSXGitHub/combine-contextual-error
Combine ContextualError and ContextualErrorKind into one
Diffstat (limited to '')
-rw-r--r--src/errors.rs58
1 files changed, 4 insertions, 54 deletions
diff --git a/src/errors.rs b/src/errors.rs
index 833e9c4..b8af25d 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),
@@ -73,58 +72,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)
}
}