summaryrefslogtreecommitdiff
path: root/racer-tracer/src/error.rs
blob: 70a9ab20a94aed454204acc0e4a33b6af84aa146 (plain)
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
34
use thiserror::Error;

#[derive(Clone, Error, Debug)]
pub enum TracerError {
    #[error("Unknown error: {message}")]
    Unknown { message: String, exit_code: i32 },

    #[error("Failed to create window: {0}")]
    FailedToCreateWindow(String),

    #[error("Failed to update window: {0}")]
    FailedToUpdateWindow(String),

    #[error("Resolution is not power of two.")]
    ResolutionIsNotPowerOfTwo(),

    #[error("Config Error ({0}): {1}")]
    Configuration(String, String),
}

impl From<TracerError> for i32 {
    fn from(tracer_error: TracerError) -> Self {
        match tracer_error {
            TracerError::Unknown {
                message: _,
                exit_code,
            } => exit_code,
            TracerError::FailedToCreateWindow(_) => 2,
            TracerError::FailedToUpdateWindow(_) => 3,
            TracerError::ResolutionIsNotPowerOfTwo() => 4,
            TracerError::Configuration(_, _) => 5,
        }
    }
}