Skip to content

Commit 0597bc5

Browse files
authored
Refactor child process handling in command_helpers
Replace wait_on_child with StderrForwarder so that we can implement reading from stdout and stderr at the same time
1 parent 0a1bc19 commit 0597bc5

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/command_helpers.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,28 @@ pub(crate) fn run_output(cmd: &mut Command, cargo_output: &CargoOutput) -> Resul
363363
.unwrap();
364364

365365
// Don't care about this output, use the normal settings
366-
wait_on_child(cmd, &mut child, cargo_output)?;
366+
StderrForwarder::new(child).forward_all();
367+
368+
let status = match child.wait() {
369+
Ok(s) => s,
370+
Err(e) => {
371+
return Err(Error::new(
372+
ErrorKind::ToolExecError,
373+
format!("failed to wait on spawned child process `{cmd:?}`: {e}"),
374+
));
375+
}
376+
};
377+
378+
cargo_output.print_debug(&status);
367379

368-
Ok(stdout)
380+
if status.success() {
381+
Ok(stdout)
382+
} else {
383+
Err(Error::new(
384+
ErrorKind::ToolExecError,
385+
format!("command did not execute successfully (status code {status}): {cmd:?}"),
386+
))
387+
}
369388
}
370389

371390
pub(crate) fn spawn(cmd: &mut Command, cargo_output: &CargoOutput) -> Result<Child, Error> {

0 commit comments

Comments
 (0)