support_kit/
errors.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use std::{io::Error, net::AddrParseError};
use thiserror::Error;

#[derive(Debug, thiserror::Error)]
pub enum OpsProcessError {
    #[error("unable to complete process: {0}")]
    ProcessExecError(#[from] std::io::Error),
    #[error("malformed command, unable to parse: {0}")]
    MalformedCommand(String),
}

#[derive(Debug, thiserror::Error)]
#[error("network init error: {0}")]
pub struct NetworkInitError(#[from] AddrParseError);

#[derive(Debug, thiserror::Error)]
#[error("invalid service label: {0}")]
pub struct InvalidServiceLabelError(#[from] std::io::Error);

#[derive(Debug, thiserror::Error)]
pub enum ServiceControlError {
    #[error("Failed to initialize service control")]
    InitializationError(#[from] Error),

    #[error("invalid service label: {0}")]
    InvalidServiceLabelError(#[from] InvalidServiceLabelError),
}

#[derive(Debug, thiserror::Error)]
pub enum SshError {
    #[error("connection error: {0}")]
    SshError(#[from] russh::Error),

    #[error("key error: {0}")]
    SshKeyError(#[from] russh::keys::Error),

    #[error("channel write error: {0}")]
    SshIoError(#[from] std::io::Error),
    #[error("authentication failed")]
    AuthenticationFailed,
}

#[derive(Debug, thiserror::Error)]
pub enum MissingDirError {
    #[error("missing home directory")]
    HomeDir,
    #[error("missing config directory")]
    ConfigDir,
}

#[derive(Debug, Error)]
pub enum SupportKitError {
    #[error("service control error: {0}")]
    ServiceControlError(#[from] ServiceControlError),

    #[error("problem finding directory: {0}")]
    MissingDirError(#[from] MissingDirError),

    #[error("problem building config: {0}")]
    ConfigBuildError(#[from] figment::Error),

    #[error("problem initializing network: {0}")]
    NetworkInitError(#[from] NetworkInitError),

    #[error("ssh error: {0}")]
    SshError(#[from] SshError),

    #[error("serde error: {0}")]
    SerdeError(#[from] serde_json::Error),

    #[error("ops process error: {0}")]
    OpsProcessError(#[from] OpsProcessError),
}