service_utils/error/
service_util_error.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
44
45
46
47
48
49
50
51
52
use std::error::Error;
use std::fmt;
use std::fmt::Formatter;

#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub enum ServiceUtilError {
    BinaryNotFound(String),
    ServiceStartFailed(String),
    ServiceAlreadyRunning(String),
    ServiceHealthcheckFailed(String),
    ServiceStopFailed(String),
    ServiceNotSupported(String),
    ServiceNotRunning(String),
    UnsupportedWaitStrategy(String),
    UnknownError(String),
}

impl Error for ServiceUtilError {}

impl fmt::Display for ServiceUtilError {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        match self {
            Self::BinaryNotFound(e) => {
                write!(f, "[ServiceUtilError]: Binary not found: {e}")
            }
            Self::ServiceStartFailed(e) => {
                write!(f, "[ServiceUtilError]: Service start failed: {e}")
            }
            Self::ServiceAlreadyRunning(e) => {
                write!(f, "[ServiceUtilError]: Service already running: {e}")
            }
            Self::ServiceHealthcheckFailed(e) => {
                write!(f, "[ServiceUtilError]: Service healthcheck failed: {e}")
            }
            Self::ServiceStopFailed(e) => {
                write!(f, "[ServiceUtilError]: Service stop failed: {e}")
            }
            Self::ServiceNotSupported(e) => {
                write!(f, "[ServiceUtilError]: Service not supported: {e}")
            }
            Self::ServiceNotRunning(e) => {
                write!(f, "[ServiceUtilError]: Service not running: {e}")
            }
            Self::UnsupportedWaitStrategy(e) => {
                write!(f, "[ServiceUtilError]: Unsupported wait strategy: {e}")
            }
            Self::UnknownError(e) => {
                write!(f, "[ServiceUtilError]: Unknown error: {e}")
            }
        }
    }
}