sui_aws_orchestrator/
error.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use std::net::SocketAddr;
5
6use reqwest::Url;
7
8#[macro_export(local_inner_macros)]
9macro_rules! ensure {
10    ($cond:expr, $e:expr) => {
11        if !($cond) {
12            return Err($e);
13        }
14    };
15}
16
17pub type SettingsResult<T> = Result<T, SettingsError>;
18
19#[derive(thiserror::Error, Debug)]
20pub enum SettingsError {
21    #[error("Failed to read settings file '{file:?}': {message}")]
22    InvalidSettings { file: String, message: String },
23
24    #[error("Failed to read token file '{file:?}': {message}")]
25    InvalidTokenFile { file: String, message: String },
26
27    #[error("Failed to read ssh public key file '{file:?}': {message}")]
28    InvalidSshPublicKeyFile { file: String, message: String },
29
30    #[error("Malformed repository url: {0:?}")]
31    MalformedRepositoryUrl(Url),
32}
33
34pub type CloudProviderResult<T> = Result<T, CloudProviderError>;
35
36#[derive(thiserror::Error, Debug)]
37pub enum CloudProviderError {
38    #[error("Failed to send server request: {0}")]
39    RequestError(String),
40
41    #[error("Unexpected response: {0}")]
42    UnexpectedResponse(String),
43
44    #[error("Received error status code ({0}): {1}")]
45    FailureResponseCode(String, String),
46
47    #[error("SSH key \"{0}\" not found")]
48    SshKeyNotFound(String),
49}
50
51pub type SshResult<T> = Result<T, SshError>;
52
53#[derive(thiserror::Error, Debug)]
54pub enum SshError {
55    #[error("Failed to load private key for {address}: {error}")]
56    PrivateKeyError {
57        address: SocketAddr,
58        error: russh_keys::Error,
59    },
60
61    #[error("Failed to create ssh session with {address}: {error}")]
62    SessionError {
63        address: SocketAddr,
64        error: russh::Error,
65    },
66
67    #[error("Failed to connect to instance {address}: {error}")]
68    ConnectionError {
69        address: SocketAddr,
70        error: russh::Error,
71    },
72
73    #[error("Remote execution on {address} returned exit code ({code}): {message}")]
74    NonZeroExitCode {
75        address: SocketAddr,
76        code: u32,
77        message: String,
78    },
79}
80
81pub type MonitorResult<T> = Result<T, MonitorError>;
82
83#[derive(thiserror::Error, Debug)]
84pub enum MonitorError {
85    #[error(transparent)]
86    SshError(#[from] SshError),
87
88    #[error("Failed to start Grafana: {0}")]
89    GrafanaError(String),
90}
91
92pub type TestbedResult<T> = Result<T, TestbedError>;
93
94#[derive(thiserror::Error, Debug)]
95pub enum TestbedError {
96    #[error(transparent)]
97    SettingsError(#[from] SettingsError),
98
99    #[error(transparent)]
100    CloudProviderError(#[from] CloudProviderError),
101
102    #[error(transparent)]
103    SshError(#[from] SshError),
104
105    #[error("Not enough instances: missing {0} instances")]
106    InsufficientCapacity(usize),
107
108    #[error(transparent)]
109    MonitorError(#[from] MonitorError),
110}