replace our DisplayWithSources with wee-woo

It's the same thing except with a nice extension trait.
This commit is contained in:
Olivia Lee 2024-12-13 20:07:10 -08:00
parent d6475eee6d
commit 41c6fc8029
No known key found for this signature in database
GPG key ID: 54D568A15B9CD1F9
4 changed files with 11 additions and 36 deletions

View file

@ -1,39 +1,11 @@
//! Error handling facilities
use std::{fmt, iter, path::PathBuf};
use std::path::PathBuf;
use thiserror::Error;
use crate::config::ListenConfig;
/// Formats an [`Error`][0] and its [`source`][1]s with a separator
///
/// [0]: std::error::Error
/// [1]: std::error::Error::source
pub(crate) struct DisplayWithSources<'a> {
/// The error (and its sources) to write
pub(crate) error: &'a dyn std::error::Error,
/// Separator to write between the original error and subsequent sources
pub(crate) infix: &'static str,
}
impl fmt::Display for DisplayWithSources<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.error)?;
let mut source = self.error.source();
source
.into_iter()
.chain(iter::from_fn(|| {
source = source.and_then(std::error::Error::source);
source
}))
.try_for_each(|source| write!(f, "{}{source}", self.infix))
}
}
/// Top-level errors
// Missing docs are allowed here since that kind of information should be
// encoded in the error messages themselves anyway.