Provide more context on process errors
authorAlex Crichton <alex@alexcrichton.com>
Wed, 18 Jun 2014 19:01:54 +0000 (12:01 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Thu, 19 Jun 2014 18:52:51 +0000 (11:52 -0700)
When printing an error for a failed process execution, the stdout/stderr are
included for inspection.

src/cargo/util/errors.rs

index 771d1dc363f48e2657bf3ab12b5c9d797eef9a25..03c38753ee8d7b40116e4eaf66620c8291570fd4 100644 (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()