eb_pipeline/
exit.rs

1//! Exit-code contract.
2
3/// All work succeeded.
4pub const OK: i32 = 0;
5/// Work was attempted and failed.
6pub const FAILED: i32 = 1;
7/// Usage error or invalid site file.
8pub const USAGE: i32 = 2;
9/// A resource is temporarily unavailable; rerun.
10pub const TEMPFAIL: i32 = 75;
11/// Refused by a precondition, by admission or by eb-staged-rebuild. Lines
12/// built before the refusal stay built.
13pub const REFUSED: i32 = 78;
14/// Interrupted by SIGINT.
15pub const SIGINT: i32 = 130;
16/// Interrupted by SIGTERM.
17pub const SIGTERM: i32 = 143;
18
19/// Table printed in `--help`.
20pub const TABLE: &str = "\
21Exit codes:
22   0  all requested work completed
23   1  work attempted and failed (a build line or a phase); see the result file
24   2  usage error, invalid site file, or a tool below its minimum version
25  75  a resource is temporarily unavailable or a step is pending; rerun
26  78  refused by a precondition, by admission or by eb-staged-rebuild; lines
27      built before the refusal stay built, see the result file
28 130  interrupted by SIGINT, after the running child ended
29 143  interrupted by SIGTERM, after the running child ended
30
31Sibling tool codes are mapped explicitly:
32  eb-stack admit    0 admitted, 78 refused, 1 failed, 2 usage
33  eb-stack shard    the code in shards.planner_exit_unsharded (default 3) means
34                    unsharded; the run continues
35  eb-staged-rebuild 2 is a refusal there; the driver records it as refused
36                    (exit 78), 75 as pending (exit 75), any other non-zero as failed
37  eb-keep-logs      rotate 75 means another rotate holds the log root's lock;
38                    the logs phase is recorded as skipped, any other non-zero
39                    as failed
40A signal (130, 143) or a usage error (2) ends the run with that code. Otherwise,
41when several apply: 1, then 78, then 75, then 0. Codes are never summed.";
42
43/// Error carrying the process exit code.
44#[derive(Debug)]
45pub struct Fail {
46    /// The exit code the program ends with, one of the constants above.
47    pub code: i32,
48    /// What went wrong; the program prints it as `ERROR [main] -: <msg>`.
49    pub msg: String,
50}
51
52impl Fail {
53    /// A failure that ends the program with `code`.
54    pub fn new(code: i32, msg: impl Into<String>) -> Self {
55        Fail {
56            code,
57            msg: msg.into(),
58        }
59    }
60    /// A failure with [`USAGE`], 2: a wrong command line, an invalid site
61    /// file or input, or a tool below its `min_version`.
62    pub fn usage(msg: impl Into<String>) -> Self {
63        Fail::new(USAGE, msg)
64    }
65}
66
67impl std::fmt::Display for Fail {
68    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
69        f.write_str(&self.msg)
70    }
71}
72
73impl std::error::Error for Fail {}