From e760633f6a9f0274a894981a90d2fb49bf96bb32 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 2 Apr 2021 13:39:56 +0100 Subject: [PATCH] InternalLogicError: Provide new() and tolerate() Signed-off-by: Ian Jackson --- src/error.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/error.rs b/src/error.rs index 06edb0be..1d1da32b 100644 --- a/src/error.rs +++ b/src/error.rs @@ -79,12 +79,18 @@ pub fn internal_error_bydebug(desc: &dyn Debug) -> IE { internal_logic_error(format!("{:?}", desc)) } +impl InternalLogicError { + pub fn new>>(desc: S) -> InternalLogicError { + let backtrace = backtrace::Backtrace::new_unresolved(); + InternalLogicError { + desc: desc.into(), + backtrace: parking_lot::Mutex::new(backtrace), + } + } +} + pub fn internal_logic_error>>(desc: S) -> IE { - let backtrace = backtrace::Backtrace::new_unresolved(); - IE::InternalLogicError(InternalLogicError { - desc: desc.into(), - backtrace: parking_lot::Mutex::new(backtrace), - }) + IE::InternalLogicError(InternalLogicError::new(desc)) } impl Debug for InternalLogicError { @@ -97,6 +103,10 @@ impl Debug for InternalLogicError { } display_as_debug!(InternalLogicError); +impl InternalLogicError { + pub fn tolerate(self) { error!("tolerating {}", self); } +} + #[derive(Clone,Error,Debug,Serialize,Deserialize)] #[error("{0}")] pub struct TokenDeliveryError(String); -- 2.30.2