isothrum_runner/error/code.rs
1//! The stable code of each failure.
2
3use serde::{Deserialize, Serialize};
4
5/// The stable code of a failure, the same in the Rust API and the event stream (`error.code`).
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, schemars::JsonSchema)]
7#[serde(rename_all = "snake_case")]
8#[non_exhaustive]
9pub enum ErrorCode {
10 /// The folder isn't a project Isothrum runs: it holds no Compose file, Vagrantfile or
11 /// Terraform module, or the files of several formats with none named.
12 ProjectInvalid,
13 /// The manifest needs something this runner doesn't do (a target that doesn't run on this
14 /// host, a delivery its driver doesn't take, an action of another driver's, a step with no
15 /// command for this host), or the call asks the run for something its target can't do (a
16 /// console into a Compose service with no VM, a Vagrant VM joined to another network).
17 Unsupported,
18 /// A file or folder couldn't be read or written, or a socket on this computer bound.
19 Io,
20 /// Another process runs an operation on this run, or holds the home's slot pick.
21 Locked,
22 /// A tool a step runs isn't installed.
23 ToolMissing,
24 /// A step's tool ran and failed.
25 ToolFailed,
26 /// A tool the run needs is installed, but got no answer from its service: Docker's engine
27 /// stopped, or quit while a step ran (the `step` says which): the message says what the tool
28 /// said.
29 ToolUnanswered,
30 /// A tool answers at a version older than the run needs.
31 ToolTooOld,
32 /// A tool refused this account (Docker's engine its socket or named pipe): the account needs
33 /// the access (a group), not the tool started.
34 ToolDenied,
35 /// A cloud refused the sign-in the run's tools use: a CLI or SSO session that ran out, an
36 /// expired token, application-default credentials gone stale, a profile never signed in.
37 /// Signing in again fixes it; the cloud refused before Terraform changed anything.
38 CredentialsExpired,
39 /// A network the run makes needs an address block another network on the engine already
40 /// holds (Docker's `Pool overlaps with other one on this address space`).
41 AddressPoolOverlap,
42 /// A step showed no progress for its time limit, or ran to the ceiling every step stops at,
43 /// and was stopped, with what it started (the `error` event's `detail` says which).
44 Timeout,
45 /// A download (what a step needs, fetched in a phase of its own before it: a Compose start's
46 /// images, a Vagrant start's boxes; or a step the manifest marks a download) showed no
47 /// progress for as long as a download may, and was stopped.
48 DownloadStalled,
49 /// A download couldn't be made: its tool failed (the message says why: a registry or a box
50 /// catalog refusing it, a name it doesn't know, the network). A failure for the network that
51 /// passes (a connection reset, refused or timed out, a gateway's 502, 503 or 504) was tried
52 /// again first, up to three more times: the message is the last try's.
53 DownloadFailed,
54 /// The run is already up.
55 AlreadyRunning,
56 /// The run is recorded on another place (server or account) than the one asked for.
57 RunningElsewhere,
58 /// A host port the run publishes is taken.
59 PortInUse,
60 /// The manifest has no park steps for that mode.
61 NotParkable,
62 /// Nothing of the run, or not every one of its machines, is left to resume.
63 NothingToResume,
64 /// The run isn't up.
65 NotRunning,
66 /// A ready condition didn't hold.
67 NotReady,
68 /// A required secret or input has no value.
69 SecretMissing,
70 /// A value or secret that can't be handed to the tools (its name empty or holding `=`, a
71 /// NUL in it).
72 InputInvalid,
73 /// A run name that can't name a run.
74 RunName,
75 /// The run's Vagrant provider is missing, unknown, not on this host, refused by the run, or
76 /// lacks its plugin, or the hypervisor lacks what it needs on this computer (virtiofsd, for a
77 /// shared folder on Linux: the `detail`'s `need`).
78 ProviderRefused,
79 /// The elevation Hyper-V's commands need couldn't be had or was lost: the permission prompt
80 /// declined or unanswered, the elevated session not started or ended before the operation
81 /// (the message says which).
82 ElevationFailed,
83 /// A machine the run doesn't have.
84 MachineUnknown,
85 /// The run has several machines the call could mean, and it named none.
86 MachineAmbiguous,
87 /// A network the run doesn't have.
88 NetworkUnknown,
89 /// A deployment can't be taken over as a run.
90 AdoptRefused,
91 /// The operation was cut short before it ended (its future dropped: an embedder's cancel, the
92 /// command line's Ctrl-C or SIGTERM); the tools it started were asked to stop, and are ended
93 /// once they have, or 30 seconds later.
94 Cancelled,
95 /// The embedder was asked for something that makes no sense (the command line: a run folder
96 /// with no manifest, a value missing or malformed), so no operation started.
97 Usage,
98 /// The machine has no graphical console to reach: its target or provider gives none (the
99 /// error says why), it isn't running, or its hypervisor doesn't say where it is.
100 NoConsole,
101 /// The server the run is on (Proxmox VE, ESXi) refused the run's credentials: its API
102 /// answered 401 or 403, or its tool said the sign-in failed (an API token revoked, a password
103 /// changed).
104 ServerAuthFailed,
105 /// A file of the runner's own (a record, a ledger entry) is there but isn't what it wrote:
106 /// not JSON, or another version's shape.
107 Corrupt,
108 /// The run's state machine has no such move (a park of a parked run, a resume of a ready
109 /// one), or a resource row can't move that way.
110 IllegalTransition,
111 /// The run moved between the read and the write that would have moved it: try again.
112 StateConflict,
113 /// The home's store was written by a newer runner.
114 StoreVersion,
115 /// The home's store isn't a database this runner reads, or holds what it doesn't write.
116 StoreCorrupt,
117 /// A live process holds the lease asked for.
118 LeaseHeld,
119}
120
121impl ErrorCode {
122 /// The code as written in JSON (`port_in_use`).
123 #[must_use]
124 pub fn as_str(self) -> &'static str {
125 match self {
126 ErrorCode::ProjectInvalid => "project_invalid",
127 ErrorCode::Unsupported => "unsupported",
128 ErrorCode::Io => "io",
129 ErrorCode::Corrupt => "corrupt",
130 ErrorCode::Locked => "locked",
131 ErrorCode::ToolMissing => "tool_missing",
132 ErrorCode::ToolFailed => "tool_failed",
133 ErrorCode::ToolUnanswered => "tool_unanswered",
134 ErrorCode::ToolTooOld => "tool_too_old",
135 ErrorCode::ToolDenied => "tool_denied",
136 ErrorCode::CredentialsExpired => "credentials_expired",
137 ErrorCode::AddressPoolOverlap => "address_pool_overlap",
138 ErrorCode::Timeout => "timeout",
139 ErrorCode::DownloadStalled => "download_stalled",
140 ErrorCode::DownloadFailed => "download_failed",
141 ErrorCode::AlreadyRunning => "already_running",
142 ErrorCode::RunningElsewhere => "running_elsewhere",
143 ErrorCode::PortInUse => "port_in_use",
144 ErrorCode::NotParkable => "not_parkable",
145 ErrorCode::NothingToResume => "nothing_to_resume",
146 ErrorCode::NotRunning => "not_running",
147 ErrorCode::NotReady => "not_ready",
148 ErrorCode::SecretMissing => "secret_missing",
149 ErrorCode::InputInvalid => "input_invalid",
150 ErrorCode::RunName => "run_name",
151 ErrorCode::ProviderRefused => "provider_refused",
152 ErrorCode::ElevationFailed => "elevation_failed",
153 ErrorCode::MachineUnknown => "machine_unknown",
154 ErrorCode::MachineAmbiguous => "machine_ambiguous",
155 ErrorCode::NetworkUnknown => "network_unknown",
156 ErrorCode::AdoptRefused => "adopt_refused",
157 ErrorCode::NoConsole => "no_console",
158 ErrorCode::Cancelled => "cancelled",
159 ErrorCode::Usage => "usage",
160 ErrorCode::ServerAuthFailed => "server_auth_failed",
161 ErrorCode::IllegalTransition => "illegal_transition",
162 ErrorCode::StateConflict => "state_conflict",
163 ErrorCode::StoreVersion => "store_version",
164 ErrorCode::StoreCorrupt => "store_corrupt",
165 ErrorCode::LeaseHeld => "lease_held",
166 }
167 }
168}
169
170impl std::fmt::Display for ErrorCode {
171 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
172 f.write_str(self.as_str())
173 }
174}