Skip to main content

stratum_node_cli/
exit.rs

1//! The process exit codes of `stratum`, stable across releases.
2//!
3//! | Code | Meaning |
4//! |---|---|
5//! | 0 | Success; for `status`, the node is `ready` |
6//! | 1 | Local failure: a key, token or resume file, the clock, or writing output |
7//! | 2 | The node could not be reached |
8//! | 3 | `status`: the node is `unconfigured` |
9//! | 4 | `status`: the node is `degraded` |
10//! | 5 | The node sent a response that does not follow the API contract |
11//! | 6 | Changes were previewed but not applied: no confirmation |
12//! | 7 | A local check refused the node's answer (claim body, manifest signature, admission notice, probe, an offered grant the manifest does not render), a profile card that does not name its owner, or an ACL that would give an application `Control` |
13//! | 8 | A bounded wait ran out: `join` (the pod was not provisioned within `--wait-secs`) or `member suspend --wait` (the suspension was not yet enforced) |
14//! | 9 | `export`: the archive was written, but an entry changed, vanished or was skipped during the walk |
15//! | 10 | Server error `bad_request` |
16//! | 11 | Server error `unauthorized` |
17//! | 12 | Server error `forbidden` |
18//! | 13 | Server error `not_found` |
19//! | 14 | Server error `conflict` |
20//! | 15 | Server error `payload_too_large` |
21//! | 16 | Server error `unsupported_media_type` |
22//! | 17 | Server error `invalid`, or a preview that reports validation errors |
23//! | 18 | Server error `too_many_challenges` |
24//! | 19 | Server error `backup_refused` |
25//! | 20 | Server error `internal` |
26//! | 21 | A server error code this client does not know |
27//! | 22 | Server error `request_timeout` |
28//! | 23 | Server error `capacity_exhausted` |
29//! | 24 | Server error `invitation_refused` |
30//! | 25 | Server error `invitations_disabled` |
31//! | 26 | Server error `gate_unavailable` |
32//! | 27 | Server error `too_many_requests` |
33//! | 28 | Server error `misdirected_request` |
34//! | 29 | Server error `method_not_allowed` |
35//! | 30 | Server error `insufficient_storage` |
36//! | 31 | `precondition_failed`: a conditional pod write found another version |
37//! | 32 | Server error `bad_gateway` (the gate got no valid answer upstream) |
38//! | 33 | Server error `gateway_timeout` (the gate's upstream did not answer in time) |
39//! | 34 | Server error `suspended` (the administrator suspended the membership the request depends on) |
40//! | 35 | Server error `archive_required` (`member remove` needs an archive from the current suspension) |
41//! | 36 | Server error `pod_data_present` (the key's earlier pod data has not been purged) |
42//! | 38 | Server error `pod_unavailable` (the pod server cannot be reached, or the node has no pods) |
43//! | 39 | Server error `workspace_unavailable` (an installation asked for a workspace and no slot is available) |
44//! | 40 | Server error `application_unavailable` (the application is not `approved`) |
45//! | 41 | Server error `image_absent` or `image_has_volumes` (approval found the image missing from the tenant daemon, or declaring a volume) |
46//! | 42 | `app install`: a container's ACL did not read back as written, or consent was refused (by the node, or because the installation stopped being `pending_consent`); consent was not sent or not recorded, and what was written was removed |
47//! | 43 | `app withdraw` or `app cleanup`: the grant's ACL cleanup is still pending for at least one container |
48//! | 44 | An ACL the client would have to rewrite holds a statement it does not evaluate; nothing was written to that ACL |
49//! | 45 | Server error `runner_unavailable` (the node's runner could not be reached or refused; an application's approval stored nothing) |
50//! | 46 | Server error `signer_unavailable` (the node committed an installation's create or consent, but the signer has not yet made or enabled its key; a rerun of the install, or `app list`, finishes a create, and the node itself finishes a consent) |
51//! | 64 | Invalid command line |
52//!
53//! Code 37 is unassigned. An earlier pre-release gave it to `lease_expired`,
54//! when that was only the gate's log name for a decision. `lease_expired` is
55//! now the pod proxy's 503 to a job, one of the [`JOB_ONLY_CODES`] no person
56//! meets, and like them exits 21 if it ever reaches the client.
57
58/// Success. For `status`, the node is `ready`.
59pub const OK: u8 = 0;
60/// A local failure: a key, token or resume file, the clock, or output.
61pub const FAILURE: u8 = 1;
62/// The node could not be reached.
63pub const UNREACHABLE: u8 = 2;
64/// `status`: the node is `unconfigured`.
65pub const UNCONFIGURED: u8 = 3;
66/// `status`: the node is `degraded`.
67pub const DEGRADED: u8 = 4;
68/// The node's response does not follow the API contract.
69pub const PROTOCOL: u8 = 5;
70/// Changes were previewed but not applied because nothing confirmed them.
71pub const NOT_CONFIRMED: u8 = 6;
72/// A local check refused the node's answer (including an offered grant the
73/// manifest does not render), or the client refused to write an ACL that
74/// would give an application `Control`.
75pub const REFUSED: u8 = 7;
76/// A bounded wait ran out. For `join`, the pod was not provisioned within
77/// the wait; rerun `join` to continue. For `member suspend --wait`, the
78/// suspension is still `enforcing`; `member show` reports when it is
79/// `enforced`.
80pub const TIMED_OUT: u8 = 8;
81/// `export`: the archive and manifest were written, but at least one entry
82/// changed, vanished or was skipped during the walk; the manifest lists
83/// them.
84pub const EXPORT_INCOMPLETE: u8 = 9;
85/// Server error `bad_request` (HTTP 400).
86pub const BAD_REQUEST: u8 = 10;
87/// Server error `unauthorized` (HTTP 401).
88pub const UNAUTHORIZED: u8 = 11;
89/// Server error `forbidden` (HTTP 403).
90pub const FORBIDDEN: u8 = 12;
91/// Server error `not_found` (HTTP 404).
92pub const NOT_FOUND: u8 = 13;
93/// Server error `conflict` (HTTP 409): stale revision, already bound or
94/// operation conflict.
95pub const CONFLICT: u8 = 14;
96/// Server error `payload_too_large` (HTTP 413).
97pub const PAYLOAD_TOO_LARGE: u8 = 15;
98/// Server error `unsupported_media_type` (HTTP 415).
99pub const UNSUPPORTED_MEDIA_TYPE: u8 = 16;
100/// Server error `invalid`, or a preview with validation errors. The node
101/// sends it with HTTP 422 on the configuration routes and with HTTP 400 for
102/// an application's manifest (with `error.field` naming the member); the
103/// exit code follows the code, not the status.
104pub const INVALID: u8 = 17;
105/// Server error `too_many_challenges` (HTTP 429).
106pub const TOO_MANY_CHALLENGES: u8 = 18;
107/// Server error `backup_refused` (HTTP 409): no backup recipient configured.
108pub const BACKUP_REFUSED: u8 = 19;
109/// Server error `internal` (HTTP 500).
110pub const INTERNAL: u8 = 20;
111/// A server error code this client does not know.
112pub const UNKNOWN_SERVER_ERROR: u8 = 21;
113/// Server error `request_timeout` (HTTP 408): the node gave up waiting for
114/// the request to arrive.
115pub const REQUEST_TIMEOUT: u8 = 22;
116/// Server error `capacity_exhausted` (HTTP 409): every tenant slot is
117/// taken; the invitation is still `issued`.
118pub const CAPACITY_EXHAUSTED: u8 = 23;
119/// Server error `invitation_refused` (HTTP 403): the invitation is unknown,
120/// expired, revoked, used or for another identity.
121pub const INVITATION_REFUSED: u8 = 24;
122/// Server error `invitations_disabled` (HTTP 403):
123/// `membership.invitations_enabled` is off.
124pub const INVITATIONS_DISABLED: u8 = 25;
125/// Server error `gate_unavailable` (HTTP 503). From the node's API: the gate
126/// could not be paused and drained for a backup. From the gate: pod writes
127/// are paused for a backup or archive, or the gate has not heard from the
128/// node's controller in time (its directory lease ran out). The gate
129/// forwarded nothing, so the request can be retried shortly.
130pub const GATE_UNAVAILABLE: u8 = 26;
131/// Server error `too_many_requests` (HTTP 429): over the admission rate
132/// limit.
133pub const TOO_MANY_REQUESTS: u8 = 27;
134/// Server error `misdirected_request` (HTTP 421): `Host` is not the node's
135/// canonical authority, so `--origin` is wrong.
136pub const MISDIRECTED_REQUEST: u8 = 28;
137/// Server error `method_not_allowed` (HTTP 405), including a `DELETE` of
138/// the root ACL.
139pub const METHOD_NOT_ALLOWED: u8 = 29;
140/// Server error `insufficient_storage` (HTTP 507): the pod volume is low
141/// and writes are stopped.
142pub const INSUFFICIENT_STORAGE: u8 = 30;
143/// `precondition_failed` (HTTP 412): `--if-match` named another version,
144/// or `--create-only` found the resource already there.
145pub const PRECONDITION_FAILED: u8 = 31;
146/// Server error `bad_gateway` (HTTP 502): the gate got no valid answer
147/// from the pod server or the controller.
148pub const BAD_GATEWAY: u8 = 32;
149/// Server error `gateway_timeout` (HTTP 504): the pod server or the
150/// controller did not answer the gate in time. A write may or may not have
151/// happened; read before writing again.
152pub const GATEWAY_TIMEOUT: u8 = 33;
153/// Server error `suspended` (HTTP 403): the administrator has suspended the
154/// membership the request depends on, the caller's own or the pod owner's.
155/// Signed requests by or to a suspended member are refused until the
156/// administrator resumes it; an existing public profile stays readable.
157pub const SUSPENDED: u8 = 34;
158/// Server error `archive_required` (HTTP 409): `member remove` needs an
159/// archive taken during the member's current suspension. Run
160/// `member archive` first, or waive it with `--no-archive`.
161pub const ARCHIVE_REQUIRED: u8 = 35;
162/// Server error `pod_data_present` (HTTP 409): an invitation or redemption
163/// for a removed or cancelled key whose earlier pod data has not been
164/// purged yet.
165pub const POD_DATA_PRESENT: u8 = 36;
166/// Server error `pod_unavailable` (HTTP 503): the pod server could not be
167/// reached or broke off (from the gate), or the node runs without pods or
168/// has no canonical origin yet (from the controller).
169pub const POD_UNAVAILABLE: u8 = 38;
170/// Server error `workspace_unavailable` (HTTP 409): the installation asked
171/// for a workspace and the node has no slot for it. In Step 3b-2 every
172/// workspace mode other than `none` gets this answer.
173pub const WORKSPACE_UNAVAILABLE: u8 = 39;
174/// Server error `application_unavailable` (HTTP 409): the application is
175/// withdrawn or disabled, so it cannot be installed.
176pub const APPLICATION_UNAVAILABLE: u8 = 40;
177/// Server error `image_absent` or `image_has_volumes` (HTTP 409): approval
178/// found the manifest's image ID missing from the tenant daemon, or found
179/// that the image declares a volume.
180pub const IMAGE_REFUSED: u8 = 41;
181/// `app install` did not complete its consent: a container's ACL did not
182/// read back as written, the installation stopped being `pending_consent`
183/// before a write, or the node refused the consent. Consent was not sent,
184/// or not recorded, and the client removed what it had written (the error
185/// lists anything it could not remove).
186pub const GRANT_NOT_CONFIRMED: u8 = 42;
187/// `app withdraw` or `app cleanup`: the withdrawn grant's ACL cleanup is
188/// still pending for at least one container; run `stratum app cleanup`
189/// again.
190pub const CLEANUP_PENDING: u8 = 43;
191/// An ACL the client would have to rewrite holds a statement it does not
192/// evaluate (an `acl:agentGroup`, an `acl:origin`, an agent class other than
193/// `foaf:Agent`, an unknown predicate or type, an ACL that is not Turtle);
194/// nothing was written to that ACL.
195pub const ACL_NOT_EVALUATED: u8 = 44;
196/// Server error `runner_unavailable` (HTTP 503): an application's approval
197/// needs the node's runner to read the image, and the runner is not
198/// configured, did not answer, or refused. Nothing was stored; approve
199/// again once the runner answers.
200pub const RUNNER_UNAVAILABLE: u8 = 45;
201/// Server error `signer_unavailable` (HTTP 503): the node committed an
202/// installation's create or consent, but the signer did not finish its step
203/// (making the application key, or confirming it enabled). The commit
204/// stays. After a create, `app install` again with the same
205/// `--operation-id`, or `app list`, finishes it (and so does the node's
206/// next start); after a consent the node's key sync keeps trying, and
207/// `app show` reports when the installation is `active`.
208pub const SIGNER_UNAVAILABLE: u8 = 46;
209/// The command line could not be parsed.
210pub const USAGE: u8 = 64;
211
212/// The server error codes no person meets, which therefore have no exit code
213/// of their own and fall to [`UNKNOWN_SERVER_ERROR`] (21) if they ever reach
214/// the client.
215///
216/// The first ten are the answers a job sees on its lease socket: the pod
217/// proxy's own refusals (`lease_revoked`, `outside_grant`, `lease_starting`,
218/// `lease_expired`, `busy`, `pod_auth_refused`) and the signer's refusals the
219/// proxy relays (`key_disabled`, `no_window`, `outside_pod`,
220/// `payload_rule`). The last two are the runner's refusals, which only the
221/// controller sees (`container_identity_conflict`, `create_expired`). No
222/// route a person calls answers any of them: a person signs with their own
223/// key, never through a lease.
224///
225/// # Examples
226///
227/// ```
228/// use stratum_node_cli::exit;
229///
230/// for code in exit::JOB_ONLY_CODES {
231///     assert_eq!(exit::for_server_code(code), exit::UNKNOWN_SERVER_ERROR);
232/// }
233/// ```
234pub const JOB_ONLY_CODES: [&str; 12] = [
235    "lease_revoked",
236    "outside_grant",
237    "lease_starting",
238    "lease_expired",
239    "busy",
240    "pod_auth_refused",
241    "key_disabled",
242    "no_window",
243    "outside_pod",
244    "payload_rule",
245    "container_identity_conflict",
246    "create_expired",
247];
248
249/// Returns the exit code for a server error code from the API contract.
250///
251/// # Examples
252///
253/// ```
254/// use stratum_node_cli::exit;
255///
256/// assert_eq!(exit::for_server_code("conflict"), exit::CONFLICT);
257/// assert_eq!(exit::for_server_code("request_timeout"), exit::REQUEST_TIMEOUT);
258/// assert_eq!(exit::for_server_code("capacity_exhausted"), exit::CAPACITY_EXHAUSTED);
259/// assert_eq!(exit::for_server_code("suspended"), exit::SUSPENDED);
260/// assert_eq!(exit::for_server_code("pod_unavailable"), exit::POD_UNAVAILABLE);
261/// assert_eq!(exit::for_server_code("image_has_volumes"), exit::IMAGE_REFUSED);
262/// assert_eq!(exit::for_server_code("runner_unavailable"), exit::RUNNER_UNAVAILABLE);
263/// assert_eq!(exit::for_server_code("signer_unavailable"), exit::SIGNER_UNAVAILABLE);
264/// assert_eq!(exit::for_server_code("something_new"), exit::UNKNOWN_SERVER_ERROR);
265/// // `lease_expired` is the pod proxy's answer to a job; no person meets it.
266/// assert_eq!(exit::for_server_code("lease_expired"), exit::UNKNOWN_SERVER_ERROR);
267/// ```
268pub fn for_server_code(code: &str) -> u8 {
269    match code {
270        "bad_request" => BAD_REQUEST,
271        "unauthorized" => UNAUTHORIZED,
272        "forbidden" | "app_forbidden" => FORBIDDEN,
273        "not_found" => NOT_FOUND,
274        "conflict" => CONFLICT,
275        "payload_too_large" => PAYLOAD_TOO_LARGE,
276        "unsupported_media_type" => UNSUPPORTED_MEDIA_TYPE,
277        "invalid" => INVALID,
278        "too_many_challenges" => TOO_MANY_CHALLENGES,
279        "backup_refused" => BACKUP_REFUSED,
280        "internal" => INTERNAL,
281        "request_timeout" => REQUEST_TIMEOUT,
282        "capacity_exhausted" => CAPACITY_EXHAUSTED,
283        "invitation_refused" => INVITATION_REFUSED,
284        "invitations_disabled" => INVITATIONS_DISABLED,
285        "gate_unavailable" => GATE_UNAVAILABLE,
286        "too_many_requests" | "rate_limited" => TOO_MANY_REQUESTS,
287        "misdirected_request" => MISDIRECTED_REQUEST,
288        "method_not_allowed" => METHOD_NOT_ALLOWED,
289        "insufficient_storage" => INSUFFICIENT_STORAGE,
290        "precondition_failed" => PRECONDITION_FAILED,
291        "bad_gateway" => BAD_GATEWAY,
292        "gateway_timeout" => GATEWAY_TIMEOUT,
293        "suspended" => SUSPENDED,
294        "archive_required" => ARCHIVE_REQUIRED,
295        "pod_data_present" => POD_DATA_PRESENT,
296        "pod_unavailable" => POD_UNAVAILABLE,
297        "workspace_unavailable" => WORKSPACE_UNAVAILABLE,
298        "application_unavailable" => APPLICATION_UNAVAILABLE,
299        "image_absent" | "image_has_volumes" => IMAGE_REFUSED,
300        "runner_unavailable" => RUNNER_UNAVAILABLE,
301        "signer_unavailable" => SIGNER_UNAVAILABLE,
302        _ => UNKNOWN_SERVER_ERROR,
303    }
304}