fix(utils): Sefely unwrap the command output (#2305)
Safely unwrap the output of the commands executed by `utils::exec_cmd`, this should avoid panics when the output of the command cannot be decoded.
This commit is contained in:
parent
47a769cdf8
commit
118f18785a
16
src/utils.rs
16
src/utils.rs
|
@ -287,8 +287,20 @@ fn internal_exec_cmd(cmd: &str, args: &[&str], time_limit: Duration) -> Option<C
|
||||||
|
|
||||||
match process.with_output_timeout(time_limit).terminating().wait() {
|
match process.with_output_timeout(time_limit).terminating().wait() {
|
||||||
Ok(Some(output)) => {
|
Ok(Some(output)) => {
|
||||||
let stdout_string = String::from_utf8(output.stdout).unwrap();
|
let stdout_string = match String::from_utf8(output.stdout) {
|
||||||
let stderr_string = String::from_utf8(output.stderr).unwrap();
|
Ok(stdout) => stdout,
|
||||||
|
Err(error) => {
|
||||||
|
log::warn!("Unable to decode stdout: {:?}", error);
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let stderr_string = match String::from_utf8(output.stderr) {
|
||||||
|
Ok(stderr) => stderr,
|
||||||
|
Err(error) => {
|
||||||
|
log::warn!("Unable to decode stderr: {:?}", error);
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
log::trace!(
|
log::trace!(
|
||||||
"stdout: {:?}, stderr: {:?}, exit code: \"{:?}\", took {:?}",
|
"stdout: {:?}, stderr: {:?}, exit code: \"{:?}\", took {:?}",
|
||||||
|
|
Loading…
Reference in New Issue