summary refs log tree commit diff stats
path: root/src/error.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/error.rs')
-rw-r--r--src/error.rs20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/error.rs b/src/error.rs
index 517b5fc..aa21021 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -1,15 +1,20 @@
+use crate::conf;
+
 // This Result is used elsewhere, not in helper()
 pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
 
-pub fn helper<T, V>(res: std::result::Result<T, V>) -> T
+pub fn helper<T, V>(res: std::result::Result<T, V>, simplified_message: &str) -> T
 where
     V: std::fmt::Debug,
 {
     match res {
         Ok(val) => val,
         Err(err) => {
-            log::error!("{:?}", err);
-            panic!("{:?}", err);
+            log::error!("{}", simplified_message);
+            if *conf::DEBUG {
+                log::error!("--> {:?}", err);
+            }
+            std::process::exit(1);
         }
     }
 }
@@ -21,14 +26,7 @@ mod tests {
     #[test]
     fn shouldnt_panic() {
         let ok: std::result::Result<&str, &str> = Ok("okay");
-        let rhs = helper(ok);
+        let rhs = helper(ok, "okay");
         assert_eq!("okay", rhs);
     }
-
-    #[test]
-    #[should_panic]
-    fn should_panic() {
-        let err: std::result::Result<&str, &str> = Err("oops");
-        helper(err);
-    }
 }