From 848a83ee70d44e23977e7b3339c959ac2d65fda1 Mon Sep 17 00:00:00 2001 From: Christopher Armstrong Date: Tue, 6 Feb 2018 00:48:07 -0600 Subject: [PATCH] take advantage of the existing `From for Error` in the implementation of `From`. This is better because it's re-using code, but also because my backtrace-handling was buggy. --- src/error.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/error.rs b/src/error.rs index 5fdc61a64..3218f410e 100644 --- a/src/error.rs +++ b/src/error.rs @@ -102,7 +102,7 @@ impl ResponseError for failure::Compat impl From for Error { fn from(err: failure::Error) -> Error { - Error { cause: Box::new(err.compat()), backtrace: None } + err.compat().into() } } @@ -662,11 +662,13 @@ pub fn ErrorInternalServerError(err: T) -> InternalError { #[cfg(test)] mod tests { + use std::env; use std::error::Error as StdError; use std::io; use httparse; use http::{StatusCode, Error as HttpError}; use cookie::ParseError as CookieParseError; + use failure; use super::*; #[test] @@ -795,4 +797,18 @@ mod tests { from!(httparse::Error::TooManyHeaders => ParseError::TooLarge); from!(httparse::Error::Version => ParseError::Version); } + + #[test] + fn failure_error() { + const NAME: &str = "RUST_BACKTRACE"; + let old_tb = env::var(NAME); + env::set_var(NAME, "0"); + let error = failure::err_msg("Hello!"); + let resp: Error = error.into(); + assert_eq!(format!("{:?}", resp), "Compat { error: ErrorMessage { msg: \"Hello!\" } }\n\n"); + match old_tb { + Ok(x) => env::set_var(NAME, x), + _ => env::remove_var(NAME), + } + } }