lorikeet_genome/utils/
errors.rs

1use std::error::Error;
2use std::fmt;
3
4#[derive(Clone)]
5pub enum BirdToolError {
6    InvalidClip(String),
7    CigarBuilderError(String),
8    IOError(String),
9    InvalidLocation(String),
10    NonContiguousIntervals(String),
11    SkipException(String),
12    InvalidVariationEvent(String),
13    ProcessPanicked(String),
14    DebugError(String),
15}
16
17// Implement std::fmt::Display for AppError
18impl fmt::Display for BirdToolError {
19    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
20        write!(f, "An Error Occurred, Please Try Again!") // user-facing output
21    }
22}
23
24// Implement std::fmt::Debug for AppError
25impl fmt::Debug for BirdToolError {
26    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
27        write!(f, "{{ file: {}, line: {} }}", file!(), line!()) // programmer-facing output
28    }
29}
30
31impl Error for BirdToolError {
32    fn description(&self) -> &str {
33        match self {
34            BirdToolError::InvalidClip(val)
35            | BirdToolError::IOError(val)
36            | BirdToolError::CigarBuilderError(val)
37            | BirdToolError::InvalidLocation(val)
38            | BirdToolError::NonContiguousIntervals(val)
39            | BirdToolError::SkipException(val)
40            | BirdToolError::InvalidVariationEvent(val)
41            | BirdToolError::ProcessPanicked(val)
42            | BirdToolError::DebugError(val) => val,
43        }
44    }
45}