mirror of
https://github.com/eyre-rs/eyre.git
synced 2025-09-28 05:21:34 +00:00
Omit '0:' if only one cause
This commit is contained in:
parent
ad275d587f
commit
b0c8c75766
@ -57,7 +57,7 @@ anyhow = "=1.0.0-alpha.1"
|
||||
Error: failed to read instrs from ./path/to/instrs.jsox
|
||||
|
||||
Caused by:
|
||||
0: No such file or directory (os error 2)
|
||||
No such file or directory (os error 2)
|
||||
```
|
||||
|
||||
- Downcasting is supported and can be by value, by shared reference, or by
|
||||
|
@ -45,7 +45,7 @@ use std::backtrace::Backtrace;
|
||||
/// Error: failed to read instrs from ./path/to/instrs.jsox
|
||||
///
|
||||
/// caused by:
|
||||
/// 0: No such file or directory (os error 2)
|
||||
/// No such file or directory (os error 2)
|
||||
/// ```
|
||||
pub trait Context<T, E> {
|
||||
/// Wrap the error value with additional context.
|
||||
|
@ -316,10 +316,13 @@ impl Debug for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
writeln!(f, "{}", self.inner.error())?;
|
||||
|
||||
let mut chain = self.chain().skip(1).enumerate();
|
||||
let mut chain = self.chain().skip(1).enumerate().peekable();
|
||||
if let Some((n, error)) = chain.next() {
|
||||
writeln!(f, "\nCaused by:")?;
|
||||
writeln!(f, " {}: {}", n, error)?;
|
||||
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)?;
|
||||
}
|
||||
|
@ -81,7 +81,7 @@
|
||||
//! Error: failed to read instrs from ./path/to/instrs.jsox
|
||||
//!
|
||||
//! Caused by:
|
||||
//! 0: No such file or directory (os error 2)
|
||||
//! No such file or directory (os error 2)
|
||||
//! ```
|
||||
//!
|
||||
//! - Downcasting is supported and can be by value, by shared reference, or by
|
||||
|
Loading…
x
Reference in New Issue
Block a user