From: Ian Jackson Date: Fri, 2 Apr 2021 12:39:56 +0000 (+0100) Subject: InternalLogicError: Provide new() and tolerate() X-Git-Tag: otter-0.5.0~322 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=e760633f6a9f0274a894981a90d2fb49bf96bb32;p=otter.git InternalLogicError: Provide new() and tolerate() Signed-off-by: Ian Jackson --- 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);