mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-16 23:31:24 +01:00
replace our DisplayWithSources with wee-woo
It's the same thing except with a nice extension trait.
This commit is contained in:
parent
d6475eee6d
commit
41c6fc8029
4 changed files with 11 additions and 36 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
|
@ -947,6 +947,7 @@ dependencies = [
|
||||||
"tracing-opentelemetry",
|
"tracing-opentelemetry",
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
"trust-dns-resolver",
|
"trust-dns-resolver",
|
||||||
|
"wee-woo",
|
||||||
"xdg",
|
"xdg",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
@ -3871,6 +3872,12 @@ dependencies = [
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wee-woo"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "005e18f8367a2e0e375c29dd4d266c97e7590ec9d64bb05dc5af054a555eda05"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "weezl"
|
name = "weezl"
|
||||||
version = "0.1.8"
|
version = "0.1.8"
|
||||||
|
|
|
||||||
|
|
@ -144,6 +144,7 @@ tracing-flame = "0.2.0"
|
||||||
tracing-opentelemetry = "0.25.0"
|
tracing-opentelemetry = "0.25.0"
|
||||||
tracing-subscriber = { version = "0.3.19", features = ["env-filter", "json"] }
|
tracing-subscriber = { version = "0.3.19", features = ["env-filter", "json"] }
|
||||||
trust-dns-resolver = "0.23.2"
|
trust-dns-resolver = "0.23.2"
|
||||||
|
wee-woo = "0.1.0"
|
||||||
xdg = "2.5.2"
|
xdg = "2.5.2"
|
||||||
|
|
||||||
[target.'cfg(unix)'.dependencies]
|
[target.'cfg(unix)'.dependencies]
|
||||||
|
|
|
||||||
30
src/error.rs
30
src/error.rs
|
|
@ -1,39 +1,11 @@
|
||||||
//! Error handling facilities
|
//! Error handling facilities
|
||||||
|
|
||||||
use std::{fmt, iter, path::PathBuf};
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use crate::config::ListenConfig;
|
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
|
/// Top-level errors
|
||||||
// Missing docs are allowed here since that kind of information should be
|
// Missing docs are allowed here since that kind of information should be
|
||||||
// encoded in the error messages themselves anyway.
|
// encoded in the error messages themselves anyway.
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ use clap::Parser;
|
||||||
#[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))]
|
#[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))]
|
||||||
use tikv_jemallocator::Jemalloc;
|
use tikv_jemallocator::Jemalloc;
|
||||||
use tracing::{error, info};
|
use tracing::{error, info};
|
||||||
|
use wee_woo::ErrorExt;
|
||||||
|
|
||||||
mod api;
|
mod api;
|
||||||
mod cli;
|
mod cli;
|
||||||
|
|
@ -100,13 +101,7 @@ async fn main() -> ExitCode {
|
||||||
return ExitCode::SUCCESS;
|
return ExitCode::SUCCESS;
|
||||||
};
|
};
|
||||||
|
|
||||||
eprintln!(
|
eprintln!("Error: {}", e.display_with_sources("\n Caused by: "));
|
||||||
"Error: {}",
|
|
||||||
error::DisplayWithSources {
|
|
||||||
error: &e,
|
|
||||||
infix: "\n Caused by: "
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
ExitCode::FAILURE
|
ExitCode::FAILURE
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue