summaryrefslogtreecommitdiff
path: root/racer-tracer/src/error.rs
blob: f32dac9120553672093c72aea53414eedc61544e (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
35
36
37
38
39
40
41
42
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),

    #[error("Unknown Material {0}.")]
    UnknownMaterial(String),

    #[error("No scene supplied.")]
    NoScene(),
}

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,
            TracerError::UnknownMaterial(_) => 6,
            TracerError::NoScene() => 7,
        }
    }
}