Provide more context on process errors

When printing an error for a failed process execution, the stdout/stderr are
included for inspection.
This commit is contained in:
Alex Crichton 2014-06-18 12:01:54 -07:00
parent 96ab5d73ff
commit 47d9bf8b4c

View File

@ -143,18 +143,30 @@ impl Show for ProcessError {
Some(ExitStatus(i)) | Some(ExitSignal(i)) => i.to_str(),
None => "never executed".to_str()
};
write!(f, "{} (status={})", self.msg, exit)
try!(write!(f, "{} (status={})", self.msg, exit));
match self.output {
Some(ref out) => {
match str::from_utf8(out.output.as_slice()) {
Some(s) if s.trim().len() > 0 => {
try!(write!(f, "\n--- stdout\n{}", s));
}
Some(..) | None => {}
}
match str::from_utf8(out.error.as_slice()) {
Some(s) if s.trim().len() > 0 => {
try!(write!(f, "\n--- stderr\n{}", s));
}
Some(..) | None => {}
}
}
None => {}
}
Ok(())
}
}
impl CargoError for ProcessError {
fn description(&self) -> String {
let exit = match self.exit {
Some(ExitStatus(i)) | Some(ExitSignal(i)) => i.to_str(),
None => "never executed".to_str()
};
format!("{} (status={})", self.msg, exit)
}
fn description(&self) -> String { self.to_str() }
fn detail(&self) -> Option<String> {
self.detail.clone()