1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-28 01:32:57 +01:00

remove Backtrace from error

This commit is contained in:
Nikolay Kim 2019-03-27 09:31:07 -07:00
parent faa3ea8e5b
commit fb9c94c3e0
2 changed files with 1 additions and 49 deletions

View File

@ -55,7 +55,6 @@ actix-utils = "0.3.4"
actix-server-config = "0.1.0"
base64 = "0.10"
backtrace = "0.3"
bitflags = "1.0"
bytes = "0.4"
byteorder = "1.2"

View File

@ -7,7 +7,6 @@ use std::{fmt, io, result};
// use actix::MailboxError;
use actix_utils::timeout::TimeoutError;
use backtrace::Backtrace;
#[cfg(feature = "cookies")]
use cookie;
use derive_more::{Display, From};
@ -47,7 +46,6 @@ pub type Result<T, E = Error> = result::Result<T, E>;
/// `ResponseError` reference from it.
pub struct Error {
cause: Box<ResponseError>,
backtrace: Option<Backtrace>,
}
impl Error {
@ -56,18 +54,6 @@ impl Error {
self.cause.as_ref()
}
/// Returns a reference to the Backtrace carried by this error, if it
/// carries one.
///
/// This uses the same `Backtrace` type that `failure` uses.
pub fn backtrace(&self) -> &Backtrace {
if let Some(bt) = self.cause.backtrace() {
bt
} else {
self.backtrace.as_ref().unwrap()
}
}
/// Converts error to a response instance and set error message as response body
pub fn response_with_message(self) -> Response {
let message = format!("{}", self);
@ -84,11 +70,6 @@ pub trait ResponseError: fmt::Debug + fmt::Display {
fn error_response(&self) -> Response {
Response::new(StatusCode::INTERNAL_SERVER_ERROR)
}
/// Response
fn backtrace(&self) -> Option<&Backtrace> {
None
}
}
impl fmt::Display for Error {
@ -99,16 +80,7 @@ impl fmt::Display for Error {
impl fmt::Debug for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if let Some(bt) = self.cause.backtrace() {
write!(f, "{:?}\n\n{:?}", &self.cause, bt)
} else {
write!(
f,
"{:?}\n\n{:?}",
&self.cause,
self.backtrace.as_ref().unwrap()
)
}
write!(f, "{:?}\n", &self.cause)
}
}
@ -122,14 +94,8 @@ impl From<Error> for Response {
/// `Error` for any error that implements `ResponseError`
impl<T: ResponseError + 'static> From<T> for Error {
fn from(err: T) -> Error {
let backtrace = if err.backtrace().is_none() {
Some(Backtrace::new())
} else {
None
};
Error {
cause: Box::new(err),
backtrace,
}
}
}
@ -412,7 +378,6 @@ impl ResponseError for ContentTypeError {
pub struct InternalError<T> {
cause: T,
status: InternalErrorType,
backtrace: Backtrace,
}
enum InternalErrorType {
@ -426,7 +391,6 @@ impl<T> InternalError<T> {
InternalError {
cause,
status: InternalErrorType::Status(status),
backtrace: Backtrace::new(),
}
}
@ -435,7 +399,6 @@ impl<T> InternalError<T> {
InternalError {
cause,
status: InternalErrorType::Response(RefCell::new(Some(response))),
backtrace: Backtrace::new(),
}
}
}
@ -462,10 +425,6 @@ impl<T> ResponseError for InternalError<T>
where
T: fmt::Debug + fmt::Display + 'static,
{
fn backtrace(&self) -> Option<&Backtrace> {
Some(&self.backtrace)
}
fn error_response(&self) -> Response {
match self.status {
InternalErrorType::Status(st) => Response::new(st),
@ -922,12 +881,6 @@ mod tests {
assert_eq!(format!("{}", e.as_response_error()), "IO error: other");
}
#[test]
fn test_backtrace() {
let e = ErrorBadRequest("err");
let _ = e.backtrace();
}
#[test]
fn test_error_cause() {
let orig = io::Error::new(io::ErrorKind::Other, "other");