support_kit/
errors.rs

1use std::{io::Error, net::AddrParseError};
2use thiserror::Error;
3
4/// The auth token failed to verify.
5#[derive(thiserror::Error, Debug)]
6#[error("Token verification failed: {0}")]
7pub struct AuthTokenVerificationFailure(#[from] jsonwebtoken::errors::Error);
8
9/// We couldn't make an auth token.
10#[derive(thiserror::Error, Debug)]
11#[error("Unable to generate auth token: {0}")]
12pub struct AuthTokenGenerationFailure(#[from] jsonwebtoken::errors::Error);
13
14/// Something went wrong with our session token.
15#[derive(thiserror::Error, Debug)]
16#[error(transparent)]
17pub enum TokenError {
18    /// An ID parse error means the ID in the token is not a valid uuid.
19    InvalidUuid(#[from] uuid::Error),
20    /// We couldn't verify the token.
21    VerificationFailed(#[from] AuthTokenVerificationFailure),
22    /// We couldn't make the token.
23    TokenGenerationFailure(#[from] AuthTokenGenerationFailure),
24}
25
26#[derive(Debug, thiserror::Error)]
27pub enum PasswordError {
28    #[error("Failed to hash password: {0}")]
29    HashError(argon2::password_hash::Error),
30}
31
32impl From<argon2::password_hash::Error> for PasswordError {
33    fn from(err: argon2::password_hash::Error) -> Self {
34        PasswordError::HashError(err)
35    }
36}
37
38#[derive(Debug, thiserror::Error)]
39pub enum BoilerplateError {
40    #[error("problem with template: {0}")]
41    TemplateError(#[from] minijinja::Error),
42    #[error("template persistence error: {0}")]
43    IoError(#[from] std::io::Error),
44}
45
46#[derive(Debug, thiserror::Error)]
47pub enum ShellCommandError {
48    #[error("unable to execute command: {0}")]
49    ExecError(#[from] std::io::Error),
50    #[error("malformed command, unable to parse: {0}")]
51    MalformedError(String),
52}
53
54#[derive(Debug, thiserror::Error)]
55#[error("network init error: {0}")]
56pub struct NetworkInitError(#[from] AddrParseError);
57
58#[derive(Debug, thiserror::Error)]
59#[error("invalid service label: {0}")]
60pub struct InvalidServiceLabelError(#[from] std::io::Error);
61
62#[derive(Debug, thiserror::Error)]
63pub enum ServiceControlError {
64    #[error("Failed to initialize service control")]
65    InitializationError(#[from] Error),
66
67    #[error("invalid service label: {0}")]
68    InvalidServiceLabelError(#[from] InvalidServiceLabelError),
69}
70
71#[derive(Debug, thiserror::Error)]
72pub enum SshError {
73    #[error("connection error: {0}")]
74    SshError(#[from] russh::Error),
75
76    #[error("key error: {0}")]
77    SshKeyError(#[from] russh::keys::Error),
78
79    #[error("channel write error: {0}")]
80    SshIoError(#[from] std::io::Error),
81
82    #[error("authentication failed")]
83    AuthenticationFailed,
84    #[error("invalid path: {0}")]
85    InvalidPath(String),
86}
87
88#[derive(Debug, thiserror::Error)]
89pub enum MissingDirError {
90    #[error("missing home directory")]
91    HomeDir,
92    #[error("missing config directory")]
93    ConfigDir,
94}
95
96#[derive(Debug, Error)]
97pub enum SupportKitError {
98    #[error("service control error: {0}")]
99    ServiceControlError(#[from] ServiceControlError),
100
101    #[error("problem finding directory: {0}")]
102    MissingDirError(#[from] MissingDirError),
103
104    #[error("problem building config: {0}")]
105    ConfigBuildError(#[from] figment::Error),
106
107    #[error("problem initializing network: {0}")]
108    NetworkInitError(#[from] NetworkInitError),
109
110    #[error("ssh error: {0}")]
111    SshError(#[from] SshError),
112
113    #[error("serde error: {0}")]
114    SerdeError(#[from] serde_json::Error),
115
116    #[error("ops process error: {0}")]
117    OpsProcessError(#[from] ShellCommandError),
118
119    #[error("boilerplate error: {0}")]
120    BoilerplateError(#[from] BoilerplateError),
121
122    #[error("token error: {0}")]
123    TokenError(#[from] TokenError),
124
125    #[error("password error: {0}")]
126    PasswordError(#[from] PasswordError),
127}