Skip to content
Myr

Simplify cause chain printing

Before adoption: this commit came in with the history the project adopted, so no landing records it.

I find this clearer because each component (the indent, the index, and the message) is each only printed in one place.

authored by David Tolnay · committed by David Tolnay · parent 2d8d0aa · Browse files · 1 file+14 added−11 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+14 added−11 removed

  • other:+14 added−11 removed

1 file+14 added−11 removed

modified:src/fmt.rs+14 added-11 removed
1use crate::error::ErrorImpl;2use crate::Chain;3use std::fmt::{self, Debug};45impl ErrorImpl<()> {6 pub(crate) fn display(&self, f: &mut fmt::Formatter) -> fmt::Result {
8 unmodified lines
15 Ok(())16 }1718 pub(crate) fn debug(&self, f: &mut fmt::Formatter) -> fmt::Result {19 let error = self.error();2021 if f.alternate() {19 return Debug::fmt(self.error(), f);22 return Debug::fmt(error, f);23 }2422 writeln!(f, "{}", self.error())?;25 writeln!(f, "{}", error)?;2624 let mut chain = self.chain().skip(1).enumerate().peekable();25 if let Some((n, error)) = chain.next() {26 write!(f, "\nCaused by:\n ")?;27 if chain.peek().is_some() {28 write!(f, "{}: ", n)?;27 if let Some(cause) = error.source() {28 write!(f, "\nCaused by:\n")?;29 let multiple = cause.source().is_some();30 for (n, error) in Chain::new(cause).enumerate() {31 write!(f, " ")?;32 if multiple {33 write!(f, "{}: ", n)?;34 }35 writeln!(f, "{}", error)?;36 }30 writeln!(f, "{}", error)?;31 for (n, error) in chain {32 writeln!(f, " {}: {}", n, error)?;33 }37 }3839 #[cfg(backtrace)]40 {
16 unmodified lines