mirror of
https://github.com/eyre-rs/eyre.git
synced 2025-10-02 07:21:36 +00:00
Render alt display on one line with colons
This commit is contained in:
parent
bba67262ed
commit
c30a32bdda
37
src/fmt.rs
37
src/fmt.rs
@ -2,39 +2,36 @@ use crate::error::ErrorImpl;
|
||||
use std::fmt::{self, Debug};
|
||||
|
||||
impl ErrorImpl<()> {
|
||||
fn print_chain(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
pub(crate) fn display(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", self.error())?;
|
||||
|
||||
let mut chain = self.chain().skip(1).enumerate().peekable();
|
||||
if let Some((n, error)) = chain.next() {
|
||||
write!(f, "\n\nCaused by:\n ")?;
|
||||
if chain.peek().is_some() {
|
||||
write!(f, "{}: ", n)?;
|
||||
}
|
||||
write!(f, "{}", error)?;
|
||||
for (n, error) in chain {
|
||||
write!(f, "\n {}: {}", n, error)?;
|
||||
if f.alternate() {
|
||||
for cause in self.chain().skip(1) {
|
||||
write!(f, ": {}", cause)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn display(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
if f.alternate() {
|
||||
self.print_chain(f)
|
||||
} else {
|
||||
write!(f, "{}", self.error())
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn debug(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
if f.alternate() {
|
||||
return Debug::fmt(self.error(), f);
|
||||
}
|
||||
|
||||
self.print_chain(f)?;
|
||||
writeln!(f)?;
|
||||
writeln!(f, "{}", self.error())?;
|
||||
|
||||
let mut chain = self.chain().skip(1).enumerate().peekable();
|
||||
if let Some((n, error)) = chain.next() {
|
||||
write!(f, "\nCaused by:\n ")?;
|
||||
if chain.peek().is_some() {
|
||||
write!(f, "{}: ", n)?;
|
||||
}
|
||||
writeln!(f, "{}", error)?;
|
||||
for (n, error) in chain {
|
||||
writeln!(f, " {}: {}", n, error)?;
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(backtrace)]
|
||||
{
|
||||
|
@ -213,10 +213,7 @@ pub use anyhow as format_err;
|
||||
/// alternate selector "{:#}".
|
||||
///
|
||||
/// ```console
|
||||
/// failed to read instrs from ./path/to/instrs.jsox
|
||||
///
|
||||
/// Caused by:
|
||||
/// No such file or directory (os error 2)
|
||||
/// failed to read instrs from ./path/to/instrs.jsox: No such file or directory (os error 2)
|
||||
/// ```
|
||||
///
|
||||
/// The Debug format "{:?}" includes your backtrace if one was captured. Note
|
||||
|
@ -18,18 +18,11 @@ oh no!\
|
||||
";
|
||||
|
||||
const EXPECTED_ALTDISPLAY_G: &str = "\
|
||||
f failed
|
||||
|
||||
Caused by:
|
||||
oh no!\
|
||||
f failed: oh no!\
|
||||
";
|
||||
|
||||
const EXPECTED_ALTDISPLAY_H: &str = "\
|
||||
g failed
|
||||
|
||||
Caused by:
|
||||
0: f failed
|
||||
1: oh no!\
|
||||
g failed: f failed: oh no!\
|
||||
";
|
||||
|
||||
const EXPECTED_DEBUG_F: &str = "\
|
||||
|
Loading…
x
Reference in New Issue
Block a user