precious_helpers/
error.rs1use thiserror::Error;
2
3#[derive(Debug, Error)]
4pub enum Error {
5 #[error(r#"Could not find "{exe:}" in your path ({path:}"#)]
6 ExecutableNotInPath { exe: String, path: String },
7
8 #[error(
9 "Got unexpected exit code {code:} from `{cmd:}`.{}",
10 exec_output_summary(stdout, stderr)
11 )]
12 UnexpectedExitCode {
13 cmd: String,
14 code: i32,
15 stdout: String,
16 stderr: String,
17 },
18
19 #[error("Ran `{cmd:}` and it was killed by signal {signal:}")]
20 ProcessKilledBySignal {
21 cmd: String,
22 signal: i32,
23 stdout: String,
24 stderr: String,
25 },
26
27 #[error("Got unexpected stderr output from `{cmd:}` with exit code {code:}:\n{stderr:}")]
28 UnexpectedStderr {
29 cmd: String,
30 code: i32,
31 stdout: String,
32 stderr: String,
33 },
34}
35
36fn exec_output_summary(stdout: &str, stderr: &str) -> String {
37 let mut output = if stdout.is_empty() {
38 String::from("\nStdout was empty.")
39 } else {
40 format!("\nStdout:\n{stdout}")
41 };
42 if stderr.is_empty() {
43 output.push_str("\nStderr was empty.");
44 } else {
45 output.push_str("\nStderr:\n");
46 output.push_str(stderr);
47 }
48 output.push('\n');
49 output
50}