~gbmor/clinte

ref: f682df279fef2e03440530e160638e9b5fe3a11e clinte/src/error.rs -rw-r--r-- 772 bytes
f682df27Benjamin Morrison version bump to 2.1.4 1 year, 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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>, simplified_message: &str) -> T
where
    V: std::fmt::Debug,
{
    match res {
        Ok(val) => val,
        Err(err) => {
            log::error!("{}", simplified_message);
            if *conf::DEBUG {
                log::error!("--> {:?}", err);
            }
            //std::process::exit(1);
            panic!("{:?}", err);
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn shouldnt_panic() {
        let ok: std::result::Result<&str, &str> = Ok("okay");
        let rhs = helper(ok, "okay");
        assert_eq!("okay", rhs);
    }
}