ckb_app_config/
exit_code.rs

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
use std::io;

/// Uses 0, 64 - 113 as exit code.
#[repr(i32)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum ExitCode {
    /// Command line arguments error.
    Cli = 64,
    /// Config options error.
    Config = 65,
    /// Operation system I/O error.
    IO = 66,
    /// General application failures.
    Failure = 113,
}

impl ExitCode {
    /// Converts into signed 32-bit integer which can be used as the process exit status.
    pub fn into(self) -> i32 {
        self as i32
    }
}

impl From<io::Error> for ExitCode {
    fn from(err: io::Error) -> ExitCode {
        eprintln!("IO Error: {err:?}");
        ExitCode::IO
    }
}

impl From<toml::de::Error> for ExitCode {
    fn from(err: toml::de::Error) -> ExitCode {
        eprintln!("Config Error: {err:?}");
        ExitCode::Config
    }
}

impl From<ckb_logger::SetLoggerError> for ExitCode {
    fn from(err: ckb_logger::SetLoggerError) -> ExitCode {
        eprintln!("Config Error: {err:?}");
        ExitCode::Config
    }
}