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) |
13//! | 10 | Server error `bad_request` |
14//! | 11 | Server error `unauthorized` |
15//! | 12 | Server error `forbidden` |
16//! | 13 | Server error `not_found` |
17//! | 14 | Server error `conflict` |
18//! | 15 | Server error `payload_too_large` |
19//! | 16 | Server error `unsupported_media_type` |
20//! | 17 | Server error `invalid`, or a preview that reports validation errors |
21//! | 18 | Server error `too_many_challenges` |
22//! | 19 | Server error `backup_refused` |
23//! | 20 | Server error `internal` |
24//! | 21 | A server error code this client does not know |
25//! | 64 | Invalid command line |
26
27/// Success. For `status`, the node is `ready`.
28pub const OK: u8 = 0;
29/// A local failure: a key, token or resume file, the clock, or output.
30pub const FAILURE: u8 = 1;
31/// The node could not be reached.
32pub const UNREACHABLE: u8 = 2;
33/// `status`: the node is `unconfigured`.
34pub const UNCONFIGURED: u8 = 3;
35/// `status`: the node is `degraded`.
36pub const DEGRADED: u8 = 4;
37/// The node's response does not follow the API contract.
38pub const PROTOCOL: u8 = 5;
39/// Changes were previewed but not applied because nothing confirmed them.
40pub const NOT_CONFIRMED: u8 = 6;
41/// A local check refused the node's answer.
42pub const REFUSED: u8 = 7;
43/// Server error `bad_request` (HTTP 400).
44pub const BAD_REQUEST: u8 = 10;
45/// Server error `unauthorized` (HTTP 401).
46pub const UNAUTHORIZED: u8 = 11;
47/// Server error `forbidden` (HTTP 403).
48pub const FORBIDDEN: u8 = 12;
49/// Server error `not_found` (HTTP 404).
50pub const NOT_FOUND: u8 = 13;
51/// Server error `conflict` (HTTP 409): stale revision, already bound or
52/// operation conflict.
53pub const CONFLICT: u8 = 14;
54/// Server error `payload_too_large` (HTTP 413).
55pub const PAYLOAD_TOO_LARGE: u8 = 15;
56/// Server error `unsupported_media_type` (HTTP 415).
57pub const UNSUPPORTED_MEDIA_TYPE: u8 = 16;
58/// Server error `invalid` (HTTP 422), or a preview with validation errors.
59pub const INVALID: u8 = 17;
60/// Server error `too_many_challenges` (HTTP 429).
61pub const TOO_MANY_CHALLENGES: u8 = 18;
62/// Server error `backup_refused` (HTTP 409): no backup recipient configured.
63pub const BACKUP_REFUSED: u8 = 19;
64/// Server error `internal` (HTTP 500).
65pub const INTERNAL: u8 = 20;
66/// A server error code this client does not know.
67pub const UNKNOWN_SERVER_ERROR: u8 = 21;
68/// The command line could not be parsed.
69pub const USAGE: u8 = 64;
70
71/// Returns the exit code for a server error code from the API contract.
72///
73/// # Examples
74///
75/// ```
76/// use stratum_node_cli::exit;
77///
78/// assert_eq!(exit::for_server_code("conflict"), exit::CONFLICT);
79/// assert_eq!(exit::for_server_code("something_new"), exit::UNKNOWN_SERVER_ERROR);
80/// ```
81pub fn for_server_code(code: &str) -> u8 {
82 match code {
83 "bad_request" => BAD_REQUEST,
84 "unauthorized" => UNAUTHORIZED,
85 "forbidden" => FORBIDDEN,
86 "not_found" => NOT_FOUND,
87 "conflict" => CONFLICT,
88 "payload_too_large" => PAYLOAD_TOO_LARGE,
89 "unsupported_media_type" => UNSUPPORTED_MEDIA_TYPE,
90 "invalid" => INVALID,
91 "too_many_challenges" => TOO_MANY_CHALLENGES,
92 "backup_refused" => BACKUP_REFUSED,
93 "internal" => INTERNAL,
94 _ => UNKNOWN_SERVER_ERROR,
95 }
96}