summaryrefslogtreecommitdiff
path: root/racer-tracer/src/error.rs
blob: e0e09340b6382730e7f485960a0b1c6d92006596 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use thiserror::Error;

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

    #[error("Error: {0}")]
    Generic(String),

    #[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("Argument parsing Error: {0}")]
    ArgumentParsingError(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,

    #[error("Image save error: {0}")]
    ImageSave(String),

    #[error("Scene failed to load: {0}")]
    SceneLoad(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,
            TracerError::UnknownMaterial(_) => 6,
            TracerError::NoScene() => 7,
            TracerError::FailedToAcquireLock(_) => 8,
            TracerError::ExitEvent => 9,
            TracerError::CancelEvent => 10,
            TracerError::Generic(_) => 11,
            TracerError::ImageSave(_) => 12,
            TracerError::SceneLoad(_) => 13,
            TracerError::ArgumentParsingError(_) => 14,
        }
    }
}