feat: removed feature display-cause

`display-cause` can be turned on with the `{:#}` format specifier
This commit is contained in:
Harald Hoyer 2021-02-02 11:16:48 +01:00 committed by Harald Hoyer
parent b2a62b2f55
commit 4eae3da3c1
Signed by: harald
GPG key ID: 900F3C4971086004
4 changed files with 11 additions and 20 deletions

View file

@ -21,7 +21,3 @@ github = { repository = "haraldh/chainerror", workflow = "Rust" }
maintenance = { status = "actively-developed" }
is-it-maintained-issue-resolution = { repository = "haraldh/chainerror" }
is-it-maintained-open-issues = { repository = "haraldh/chainerror" }
[features]
default = []
display-cause = []

View file

@ -51,6 +51,10 @@ fn func1() -> ChainResult<(), Func1Error> {
fn main() {
if let Err(e) = func1() {
eprintln!("\nDisplay Error {{}}:\n{}", e);
eprintln!("\nAlternative Display Error {{:#}}:\n{:#}", e);
eprintln!("\nDebug Error {{:?}}:\n{:?}", e);
eprintln!("\nAlternative Debug Error {{:#?}}:\n{:#?}\n", e);

View file

@ -92,11 +92,6 @@
//!
//! Debug information is worth it!
//!
//! ## Features
//!
//! `display-cause`
//! : turn on printing a backtrace of the errors in `Display`
//!
//! # Tutorial
//!
//! Read the [Tutorial](https://haraldh.github.io/chainerror/tutorial1.html)
@ -596,13 +591,12 @@ impl<T: 'static + Display + Debug> Display for ChainError<T> {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
write!(f, "{}", self.kind)?;
#[cfg(feature = "display-cause")]
{
if f.alternate() {
if let Some(e) = self.source() {
writeln!(f, "\nCaused by:")?;
Display::fmt(&e, f)?;
write!(f, "\nCaused by:\n {:#}", &e)?;
}
}
Ok(())
}
}
@ -633,8 +627,7 @@ impl<T: 'static + Display + Debug> Debug for ChainError<T> {
}
if let Some(e) = self.source() {
writeln!(f, "\nCaused by:")?;
Debug::fmt(&e, f)?;
write!(f, "\nCaused by:\n{:?}", &e)?;
}
Ok(())
}

View file

@ -2,7 +2,6 @@ use chainerror::prelude::v1::*;
use std::error::Error;
use std::io;
#[cfg(not(feature = "display-cause"))]
#[test]
fn test_iter() -> Result<(), Box<dyn Error + Send + Sync>> {
use std::fmt::Write;
@ -32,9 +31,8 @@ fn test_iter() -> Result<(), Box<dyn Error + Send + Sync>> {
Ok(())
}
#[cfg(feature = "display-cause")]
#[test]
fn test_iter() -> Result<(), Box<dyn Error + Send + Sync>> {
fn test_iter_alternate() -> Result<(), Box<dyn Error + Send + Sync>> {
let err: Result<(), _> = Err(io::Error::from(io::ErrorKind::NotFound));
let err = err.context("1");
let err = err.context("2");
@ -44,9 +42,9 @@ fn test_iter() -> Result<(), Box<dyn Error + Send + Sync>> {
let err = err.context("6");
let err = err.err().unwrap();
let res = err.to_string();
let res = format!("{:#}", err);
assert_eq!(res, "6\nCaused by:\n5\nCaused by:\n4\nCaused by:\n3\nCaused by:\n2\nCaused by:\n1\nCaused by:\nentity not found");
assert_eq!(res, format!("6\nCaused by:\n 5\nCaused by:\n 4\nCaused by:\n 3\nCaused by:\n 2\nCaused by:\n 1\nCaused by:\n {:#}", io::Error::from(io::ErrorKind::NotFound)));
let io_error: Option<&io::Error> = err
.iter()