forked from metalbear-co/mirrord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.rs
203 lines (191 loc) · 8.31 KB
/
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
use std::path::PathBuf;
use miette::Diagnostic;
use mirrord_console::error::ConsoleError;
use mirrord_kube::error::KubeApiError;
use mirrord_operator::client::OperatorApiError;
use thiserror::Error;
pub(crate) type Result<T, E = CliError> = miette::Result<T, E>;
const GENERAL_HELP: &str = r#"
- If you're still stuck:
>> Please open a new bug report at https://github.com/metalbear-co/mirrord/issues/new/choose
>> Or join our Discord https://discord.gg/metalbear and request help in #mirrord-help
>> Or email us at hi@metalbear.co
"#;
#[derive(Debug, Error, Diagnostic)]
pub(crate) enum InternalProxyError {
#[error("Couldn't listen for connections {0:#?}")]
ListenError(std::io::Error),
#[error("Couldn't get local port{0:#?}")]
LocalPortError(std::io::Error),
#[error("Couldn't accept connection before timeout")]
FirstConnectionTimeout,
#[error("Couldn't accept connection {0:#?}")]
AcceptError(std::io::Error),
#[error("Couldn't connect to operator ")]
OperatorConnectionError,
#[error("Couldn't connect to agent via TCP {0:#?}")]
TcpConnectError(std::io::Error),
#[error("Agent closed connection on ping/pong, image version/arch mismatch?")]
AgentClosedConnection,
#[error("Ping error {0:#?} - image version/arch mismatch?")]
PingError(#[from] tokio::sync::mpsc::error::SendError<mirrord_protocol::ClientMessage>),
#[error("Set sid failed {0:#?}, please report a bug")]
SetSidError(nix::Error),
}
#[derive(Debug, Error, Diagnostic)]
pub(crate) enum CliError {
#[error("Failed to connect to the operator. We have found the operator and unable to connect to it. {0:#?}")]
#[diagnostic(help(
r#"
Please check the following:
1. The operator is running and the logs are not showing any errors.
2. You have sufficient permissions to port forward to the operator.
{GENERAL_HELP}"#
))]
OperatorConnectionFailed(#[from] OperatorApiError),
#[error("Failed to create Kubernetes API. {0:#?}")]
#[diagnostic(help(
r#"
Please check that Kubernetes is configured correctly.
Test your connection with `kubectl get pods`.
{GENERAL_HELP}"#
))]
KubernetesApiFailed(#[from] KubeApiError),
#[error("Agent wasn't ready in time")]
#[diagnostic(help(
r#"
Please check the status of the agent pod, using `kubectl get pods` in the relevant namespace.
Make sure it is able to fetch the agent image, it didn't fail due to lack of resources, etc.
{GENERAL_HELP}"#
))]
AgentReadyTimeout,
#[error("Create agent failed. {0:#?}")]
#[diagnostic(help(
r#"
Please check the status of the agent pod, using `kubectl get pods` in the relevant namespace.
Make sure it is able to fetch the agent image, it didn't fail due to lack of resources, etc.
{GENERAL_HELP}"#
))]
CreateAgentFailed(KubeApiError),
#[error("Failed to connect to the created agent. {0:#?}")]
#[diagnostic(help(
r#"
Please check the following:
1. The agent is running and the logs are not showing any errors.
2. You have sufficient permissions to port forward to the agent.
{GENERAL_HELP}"#
))]
AgentConnectionFailed(KubeApiError),
#[error("Invalid environment configuration. Include {0:#?} and exclude {1:#?}")]
#[diagnostic(help(
r#"
mirrord doesn't support specifying both
`OVERRIDE_ENV_VARS_EXCLUDE` and `OVERRIDE_ENV_VARS_INCLUDE` at the same time!
> Use either `--override_env_vars_exclude` or `--override_env_vars_include`.
>> If you want to include all, use `--override_env_vars_include="*"`.
{GENERAL_HELP}"#
))]
InvalidEnvConfig(String, String),
#[error("Invalid message received from agent {0:#?}")]
#[diagnostic(help(
"This is a bug. Please report it in our Discord or GitHub repository. {GENERAL_HELP}"
))]
InvalidMessage(String),
#[error("Timeout waiting for remote environment variables.")]
#[diagnostic(help(
"Please make sure the agent is running and the logs are not showing any errors.{GENERAL_HELP}"
))]
GetEnvironmentTimeout,
#[error("Failed to execute binary `{0:#?}` with args `{1:#?}`")]
#[diagnostic(help(
r#"
Please open an issue on our GitHub repository with binary information:
1. How it was compiled/built.
2. `file` output on it.
3. Operating system
4. Any extra information you might have.
5. If you can provide way to build the binary, that would be great.
{GENERAL_HELP}"#
))]
BinaryExecuteFailed(String, Vec<String>),
#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
#[error("Binary is SIP protected and rosetta is missing")]
#[diagnostic(help(
r#"
The file you are trying to run, `{0:#?}`, is either SIP protected or a script with a
shebang that leads to a SIP protected binary. In order to bypass SIP protection,
mirrord creates a non-SIP version of the binary and runs that one instead of the
protected one. The non-SIP version is however an x86_64 file, so in order to run
it on apple hardware, rosetta has to be installed.
Rosetta can be installed by runnning:
softwareupdate --install-rosetta
{GENERAL_HELP}
"#
))]
RosettaMissing(String),
#[error("Configuration file parsing failed - {0:#?}")]
#[diagnostic(help(
r#"Configuration file parsing failed. Inspect your config file or arguments provided.{GENERAL_HELP}"#
))]
ConfigError(#[from] mirrord_config::config::ConfigError),
#[error("Error with config file's path at `{0:#?}`: `{1:#?}`")]
#[diagnostic(help(
"Please check that the path is correct and that you have permissions to read it.{GENERAL_HELP}",
))]
ConfigFilePathError(PathBuf, std::io::Error),
#[error("License Error: `{0:#?}`")]
#[diagnostic(help(
r#"Check if license is valid and make sure you have working network connection{GENERAL_HELP}"#
))]
LicenseError(reqwest::Error),
#[error("Creating kubernetes manifest yaml file failed with err : {0:#?}")]
#[diagnostic(help(
r#"Check if you have permissions to write to the file and/or directory exists{GENERAL_HELP}"#
))]
ManifestFileError(std::io::Error),
#[error("Authentication issue: `{0:#?}`")]
AuthError(#[from] mirrord_auth::AuthenticationError),
#[cfg(target_os = "macos")]
#[error("SIP Error: `{0:#?}`")]
#[diagnostic(help(
r#"This issue is related to SIP on macOS. Please create an issue or consult with us on Discord
{GENERAL_HELP}"#
))]
SipError(#[from] mirrord_sip::SipError),
#[error("Operator setup error: `{0:#?}`")]
SetupError(#[from] mirrord_operator::setup::SetupError),
#[error("Error extracting layer to `{0:#?}`: `{1:#?}`")]
#[diagnostic(help("Please report a bug.{GENERAL_HELP}",))]
LayerExtractFailed(PathBuf, std::io::Error),
#[error("JSON Serialization error: `{0:#?}`")]
JsonSerializeError(#[from] serde_json::Error),
#[error("Failed connecting to mirrord console for logging {0:#?}")]
ConsoleConnectError(#[from] ConsoleError),
#[error("Couldn't get stdout of internal proxy")]
#[diagnostic(help(
r#"This is a bug. Please report it in our Discord or GitHub repository. {GENERAL_HELP}"#
))]
InternalProxyStdoutError,
#[error("Couldn't get port of internal proxy")]
#[diagnostic(help(
r#"This is a bug. Please report it in our Discord or GitHub repository. {GENERAL_HELP}"#
))]
InternalProxyPortReadError,
#[error("Internal proxy read error: {0:#?}")]
InternalProxyReadError(std::io::Error),
#[error("Internal proxy error: {0:#?}")]
InternalProxyError(#[from] InternalProxyError),
#[error("Getting cli path failed {0:#?}")]
CliPathError(std::io::Error),
#[error("Executing internal proxy failed {0:#?}")]
InternalProxyExecutionFailed(std::io::Error),
#[error("Internal proxy port parse error: {0:#?}")]
InternalProxyPortParseError(std::num::ParseIntError),
#[error("Internal proxy wait error: {0:#?}")]
InternalProxyWaitError(std::io::Error),
#[error("Waitlist registration failed.")]
#[diagnostic(help("Please check the email provided and internet connection.{GENERAL_HELP}"))]
WaitlistError(reqwest::Error),
#[error("{0} is not compatible with a targetless agent, please either disable this option or specify a target.")]
IncompatibleWithTargetless(String),
}