just/
output_error.rs

1use super::*;
2
3#[derive(Debug)]
4pub(crate) enum OutputError {
5  /// Non-zero exit code
6  Code(i32),
7  /// Interrupted by signal
8  Interrupted(Signal),
9  /// IO error
10  Io(io::Error),
11  /// Terminated by signal
12  Signal(i32),
13  /// Unknown failure
14  Unknown,
15  /// Stdout not UTF-8
16  Utf8(str::Utf8Error),
17}
18
19impl OutputError {
20  pub(crate) fn result_from_exit_status(exit_status: ExitStatus) -> Result<(), OutputError> {
21    match exit_status.code() {
22      Some(0) => Ok(()),
23      Some(code) => Err(Self::Code(code)),
24      None => match Platform::signal_from_exit_status(exit_status) {
25        Some(signal) => Err(Self::Signal(signal)),
26        None => Err(Self::Unknown),
27      },
28    }
29  }
30}
31
32impl Display for OutputError {
33  fn fmt(&self, f: &mut Formatter) -> fmt::Result {
34    match *self {
35      Self::Code(code) => write!(f, "Process exited with status code {code}"),
36      Self::Interrupted(signal) => write!(
37        f,
38        "Process succeded but `just` was interrupted by signal {signal}"
39      ),
40      Self::Io(ref io_error) => write!(f, "Error executing process: {io_error}"),
41      Self::Signal(signal) => write!(f, "Process terminated by signal {signal}"),
42      Self::Unknown => write!(f, "Process experienced an unknown failure"),
43      Self::Utf8(ref err) => write!(f, "Could not convert process stdout to UTF-8: {err}"),
44    }
45  }
46}