chiark / gitweb /
InternalLogicError: Provide new() and tolerate()
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 2 Apr 2021 12:39:56 +0000 (13:39 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 2 Apr 2021 15:16:29 +0000 (16:16 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/error.rs

index 06edb0bedbe0de9915d6fcc481a69f329dda42e6..1d1da32b0f70c8deb802ffc1757fc73a711b4f86 100644 (file)
@@ -79,12 +79,18 @@ pub fn internal_error_bydebug(desc: &dyn Debug) -> IE {
   internal_logic_error(format!("{:?}", desc))
 }
 
+impl InternalLogicError {
+  pub fn new<S: Into<Cow<'static, str>>>(desc: S) -> InternalLogicError {
+    let backtrace = backtrace::Backtrace::new_unresolved();
+    InternalLogicError {
+      desc: desc.into(),
+      backtrace: parking_lot::Mutex::new(backtrace),
+    }
+  }
+}
+
 pub fn internal_logic_error<S: Into<Cow<'static, str>>>(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);