summaryrefslogtreecommitdiffstats
path: root/lib/core/libimagerror/src/trace.rs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/core/libimagerror/src/trace.rs')
-rw-r--r--lib/core/libimagerror/src/trace.rs52
1 files changed, 17 insertions, 35 deletions
diff --git a/lib/core/libimagerror/src/trace.rs b/lib/core/libimagerror/src/trace.rs
index f990f1b1..e7bb5a39 100644
--- a/lib/core/libimagerror/src/trace.rs
+++ b/lib/core/libimagerror/src/trace.rs
@@ -18,48 +18,30 @@
//
use std::process::exit;
-use std::fmt::Display;
-use std::fmt::Formatter;
-use std::fmt::Result as FmtResult;
+
use anyhow::Error;
use ansi_term::Colour::Red;
-struct ImagTrace<'a, T: 'a + ?Sized>(&'a T);
-
-impl<'a, T: 'a + ?Sized> ImagTrace<'a, T> {
- fn new(d: &'a T) -> ImagTrace<'a, T> {
- ImagTrace(d)
- }
-}
-
-impl<'a> Display for ImagTrace<'a, Error>
-{
- fn fmt(&self, fmt: &mut Formatter) -> FmtResult {
- writeln!(fmt, "{}: {}", Red.blink().paint("ERROR[ 0]"), self.0)?;
-
- {
- for (i, cause) in self.0.iter_causes().enumerate() {
- writeln!(fmt,
- "{prefix}: {error}",
- prefix = Red.blink().paint(format!("ERROR[{:>4}]", i + 1)),
- error = cause)?;
- }
- }
-
- writeln!(fmt, "{}", Red.paint("--- BACKTRACE ---"))?;
- writeln!(fmt, "{:?}", self.0.backtrace())?;
-
- Ok(())
- }
-}
-
-
pub fn trace_error(e: &Error) {
- eprintln!("{}", ImagTrace::new(e));
+ eprintln!("{}: {}", Red.blink().paint("ERROR[ 0]"), e);
+ let mut i = 0;
+ e.chain().skip(1).for_each(|cause| {
+ eprintln!("{prefix}: {error}",
+ prefix = Red.blink().paint(format!("ERROR[{:>4}]", i + 1)),
+ error = cause);
+ i += 1;
+ });
}
pub fn trace_error_dbg(e: &Error) {
- debug!("{}", ImagTrace::new(e));
+ debug!("{}: {}", Red.blink().paint("ERROR[ 0]"), e);
+ let mut i = 0;
+ e.chain().skip(1).for_each(|cause| {
+ debug!("{prefix}: {error}",
+ prefix = Red.blink().paint(format!("ERROR[{:>4}]", i + 1)),
+ error = cause);
+ i += 1;
+ });
}
/// Helper functions for `Result<T, E>` types to reduce overhead in the following situations: