Improve display for tor-dircache errors.
These errors no longer use Debug to dump the `Option<SourceInfo>`, but instead produce reasonable text. Also, I've fixed the SourceInfo Display implementation so that it now says that it got the error "from $source via $circuit" rather than the other way around.
This commit is contained in:
parent
d681967b61
commit
82766e74e4
|
@ -18,7 +18,7 @@ pub enum Error {
|
|||
CircMgr(#[from] tor_circmgr::Error),
|
||||
|
||||
/// An error that has occurred after we have contacted a directory cache and made a circuit to it.
|
||||
#[error("Error fetching directory information from {source:?}")]
|
||||
#[error("Error fetching directory information{}", FromSource(.source))]
|
||||
RequestFailed {
|
||||
/// The source that gave us this error.
|
||||
source: Option<SourceInfo>,
|
||||
|
@ -29,6 +29,19 @@ pub enum Error {
|
|||
},
|
||||
}
|
||||
|
||||
/// Helper type to display an optional source of directory information.
|
||||
struct FromSource<'a>(&'a Option<SourceInfo>);
|
||||
|
||||
impl std::fmt::Display for FromSource<'_> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
if let Some(si) = self.0 {
|
||||
write!(f, " from {}", si)
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// An error originating from the tor-dirclient crate.
|
||||
#[derive(Error, Debug, Clone)]
|
||||
#[non_exhaustive]
|
||||
|
|
|
@ -24,7 +24,7 @@ pub struct DirResponse {
|
|||
/// We use this to remember when a request has failed, so we can
|
||||
/// abandon the circuit.
|
||||
#[derive(Debug, Clone, derive_more::Display)]
|
||||
#[display(fmt = "{} via {}", circuit, cache_id)]
|
||||
#[display(fmt = "{} via {}", cache_id, circuit)]
|
||||
pub struct SourceInfo {
|
||||
/// Unique identifier for the circuit we're using
|
||||
circuit: UniqId,
|
||||
|
|
Loading…
Reference in New Issue