-
Notifications
You must be signed in to change notification settings - Fork 535
/
Copy pathoutput_error.rs
46 lines (43 loc) · 1.33 KB
/
output_error.rs
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
use super::*;
#[derive(Debug)]
pub(crate) enum OutputError {
/// Non-zero exit code
Code(i32),
/// Interrupted by signal
Interrupted(Signal),
/// IO error
Io(io::Error),
/// Terminated by signal
Signal(i32),
/// Unknown failure
Unknown,
/// Stdout not UTF-8
Utf8(str::Utf8Error),
}
impl OutputError {
pub(crate) fn result_from_exit_status(exit_status: ExitStatus) -> Result<(), OutputError> {
match exit_status.code() {
Some(0) => Ok(()),
Some(code) => Err(Self::Code(code)),
None => match Platform::signal_from_exit_status(exit_status) {
Some(signal) => Err(Self::Signal(signal)),
None => Err(Self::Unknown),
},
}
}
}
impl Display for OutputError {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match *self {
Self::Code(code) => write!(f, "Process exited with status code {code}"),
Self::Interrupted(signal) => write!(
f,
"Process succeded but `just` was interrupted by signal {signal}"
),
Self::Io(ref io_error) => write!(f, "Error executing process: {io_error}"),
Self::Signal(signal) => write!(f, "Process terminated by signal {signal}"),
Self::Unknown => write!(f, "Process experienced an unknown failure"),
Self::Utf8(ref err) => write!(f, "Could not convert process stdout to UTF-8: {err}"),
}
}
}