1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use std::{error, fmt};
#[derive(Debug)]
pub enum CommandError {
Exec(std::io::Error),
CommandFailed {
exit_code: Option<i32>,
stderr: Vec<u8>,
},
Json(serde_json::Error),
}
impl fmt::Display for CommandError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::Exec(_) => {
write!(f, "`cargo nextest` process execution failed")
}
Self::CommandFailed { exit_code, stderr } => {
let exit_code_str =
exit_code.map_or(String::new(), |code| format!(" with exit code {}", code));
let stderr = String::from_utf8_lossy(stderr);
write!(
f,
"`cargo nextest` failed{}, stderr:\n{}\n",
exit_code_str, stderr
)
}
Self::Json(_) => {
write!(f, "parsing `cargo nextest` JSON output failed")
}
}
}
}
impl error::Error for CommandError {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match self {
Self::Exec(err) => Some(err),
Self::CommandFailed { .. } => None,
Self::Json(err) => Some(err),
}
}
}