summaryrefslogtreecommitdiffstats
path: root/crates/core/tedge/src/system_services/error.rs
blob: 1b2e8c1aa51554fd2eac0856d791d043929d0dcd (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
#[derive(thiserror::Error, Debug)]
pub enum SystemServiceError {
    #[error(transparent)]
    IoError(#[from] std::io::Error),

    #[error(transparent)]
    SystemdError(#[from] SystemdError),

    #[error(transparent)]
    OpenRcServiceError(#[from] OpenRcServiceError),

    #[error(transparent)]
    BsdServiceError(#[from] BsdServiceError),

    #[error("Unexpected value for exit status.")]
    UnexpectedExitStatus,

    #[error("Unsupported operation.")]
    UnsupportedOperation,

    #[error("Service Manager: '{0}' is not available on the system or elevated permissions have not been granted.")]
    ServiceManagerUnavailable(String),
}

/// The error type used by the `SystemdServiceManager`
#[derive(thiserror::Error, Debug)]
pub enum SystemdError {
    #[error("Systemd returned unspecific error for service {service} while performing {cmd} it.\nHint: {hint}")]
    UnspecificError {
        service: &'static str,
        cmd: &'static str,
        hint: &'static str,
    },

    #[error("Service {service} not found. Install {service} to use this command.")]
    ServiceNotFound { service: &'static str },

    #[error("Service {service} not loaded.")]
    ServiceNotLoaded { service: &'static str },

    #[error("Returned exit code: '{code:?}' for: systemd' is unhandled.")]
    UnhandledReturnCode { code: i32 },
}

/// The error type used by the `OpenRcServiceManager`
#[derive(thiserror::Error, Debug)]
pub enum OpenRcServiceError {
    #[error("Service command <{service_command:?}> failed with code: {code:?}.")]
    ServiceCommandFailed {
        service_command: String,
        code: Option<i32>,
    },
}

/// The error type used by the `BsdServiceManager`
#[derive(thiserror::Error, Debug)]
pub enum BsdServiceError {
    #[error("Service command <{service_command:?}> failed with code: {code:?}.")]
    ServiceCommandFailed {
        service_command: String,
        code: Option<i32>,
    },
}