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