summaryrefslogtreecommitdiffstats
path: root/src/wait/error.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/wait/error.rs')
-rw-r--r--src/wait/error.rs26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/wait/error.rs b/src/wait/error.rs
index bb95e81..169097d 100644
--- a/src/wait/error.rs
+++ b/src/wait/error.rs
@@ -2,11 +2,22 @@ use nix;
use std::time::Duration;
#[derive(Debug)]
+pub struct ProcessSignalInfo {
+ pub pid: nix::unistd::Pid,
+ pub signal: nix::sys::signal::Signal,
+ pub coredump: bool
+}
+
+#[derive(Debug)]
pub enum WaitError {
TimedOut(Duration),
- OsError(nix::Error)
+ ReturnNonZero(i32, nix::unistd::Pid),
+ Signaled(ProcessSignalInfo),
+ OsError(nix::Error),
+ NotExited
}
+
impl From<nix::Error> for WaitError {
fn from(err: nix::Error) -> Self {
WaitError::OsError(err)
@@ -17,7 +28,13 @@ impl std::fmt::Display for WaitError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match *self {
WaitError::TimedOut(dur) => write!(f, "process timed out in {:?}", dur),
- WaitError::OsError(err) => err.fmt(f)
+ WaitError::ReturnNonZero(ret, pid) =>
+ write!(f, "process exited with non-zero exit code ({}). was {}", ret, pid),
+ WaitError::Signaled(ref info) =>
+ write!(f, "process killed by {} {}. was {}",
+ info.signal, if info.coredump {"(core dumped)"} else {""}, info.pid),
+ WaitError::OsError(err) => err.fmt(f),
+ WaitError::NotExited => write!(f, "process signaled, but not exited")
}
}
}
@@ -25,7 +42,10 @@ impl std::fmt::Display for WaitError {
impl std::error::Error for WaitError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match *self {
- WaitError::TimedOut(_) => None,
+ WaitError::TimedOut(_) |
+ WaitError::ReturnNonZero(_, _) |
+ WaitError::Signaled(_) |
+ WaitError::NotExited => None,
WaitError::OsError(ref e) => Some(e)
}
}