From efc4cc5b1a665cded9e9e151d41dbd90feda2143 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 1 Jun 2021 21:33:41 +0100 Subject: [PATCH] errors: Rename AnyhowDisplay and provide .d() and use it Signed-off-by: Ian Jackson --- src/error.rs | 2 +- src/sshkeys.rs | 2 +- src/utils.rs | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/error.rs b/src/error.rs index 65dc85ed..ea9f1554 100644 --- a/src/error.rs +++ b/src/error.rs @@ -52,7 +52,7 @@ pub enum InternalError { StringFormatting(#[from] fmt::Error), #[error("JSON deserialisation error: {0:?}")] JSONEncode(serde_json::Error), - #[error("Server error: {}", AnyhowFormat(&.0))] + #[error("Server error: {}", .0.d())] Anyhow(#[from] anyhow::Error), #[error("Game contains only partial data for player, or account missing")] PartialPlayerData, diff --git a/src/sshkeys.rs b/src/sshkeys.rs index 83797f13..7ddacc8d 100644 --- a/src/sshkeys.rs +++ b/src/sshkeys.rs @@ -80,7 +80,7 @@ pub struct AuthKeysManipError { } impl From for AuthKeysManipError { fn from(ae: anyhow::Error) -> AuthKeysManipError { error!("authorized_keys manipulation error: {}: {}", - &config().authorized_keys, AnyhowFormat(&ae)); + &config().authorized_keys, ae.d()); AuthKeysManipError { } } } diff --git a/src/utils.rs b/src/utils.rs index 01f9bd73..de0fced0 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -644,8 +644,8 @@ impl IndexVec where I: index_vec::Idx { } #[derive(Debug)] -pub struct AnyhowFormat<'a>(pub &'a anyhow::Error); -impl Display for AnyhowFormat<'_> { +pub struct AnyhowDisplay<'a>(pub &'a anyhow::Error); +impl Display for AnyhowDisplay<'_> { #[throws(fmt::Error)] fn fmt(&self, f: &mut fmt::Formatter) { let mut delim = ""; @@ -670,6 +670,8 @@ impl anyhow::Error { Ok(()) } + fn d(&self) -> AnyhowDisplay<'_> { AnyhowDisplay(self) } + fn end_process(self, estatus: u8) -> ! { #[derive(Default,Debug)] struct Sol { any: bool } impl Sol { -- 2.30.2