summaryrefslogtreecommitdiff
path: root/racer-tracer/src/error.rs
blob: 6e1b305e43c048f1b396c11963677f3257f5f13f (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
43
44
45
46
47
48
49
50
51
52
53
54
use thiserror::Error;

#[derive(Clone, Error, Debug, PartialEq, Eq)]
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(),

    #[error("Failed to acquire lock \"{0}\"")]
    FailedToAcquireLock(String),

    #[error("Exit event")]
    ExitEvent,

    #[error("Cancel event")]
    CancelEvent,
}

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,
            TracerError::FailedToAcquireLock(_) => 8,
            TracerError::ExitEvent => 9,
            TracerError::CancelEvent => 10,
        }
    }
}