From 751dd5fa1d188739fbf0b8da31b3f54a2c2a6e18 Mon Sep 17 00:00:00 2001 From: BD103 <59022059+BD103@users.noreply.github.com> Date: Tue, 7 May 2024 22:27:17 -0400 Subject: [PATCH] refactor: `run_cargo_command_with_json` --- tools/ci/src/commands/mod.rs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/tools/ci/src/commands/mod.rs b/tools/ci/src/commands/mod.rs index 8f1523a8c8171..999fbbdff6138 100644 --- a/tools/ci/src/commands/mod.rs +++ b/tools/ci/src/commands/mod.rs @@ -79,6 +79,7 @@ pub fn run_cargo_command( .args(["run", channel.as_str(), "cargo", cargo_command]) .args(args) .envs(env.iter().copied()) + // Execute the command and collect its exit code. .status() .map_err(|err| eprintln!("{err}")) .and_then(status_to_result) @@ -107,11 +108,13 @@ pub fn run_cargo_command_with_json( channel.as_str(), "cargo", cargo_command, + // Here we specify that we want JSON output. "--message-format", "json", ]) .args(flags) .envs(env.iter().copied()) + // TODO: What's this line doing? .stdout(Stdio::piped()) .spawn() .map_err(|err| eprintln!("{err}"))?; @@ -121,15 +124,11 @@ pub fn run_cargo_command_with_json( unreachable!("Child was configured to pipe it's stdout to use but didn't") }; - match JsonCommandOutput::from_cargo_output(command_out, command_name.to_string()) { - Ok(json) => { - let _ = child.wait(); // Don't just leave the child running in the background - Ok(json) - } - Err(err) => { - let _ = child.wait(); - eprintln!("{err}"); - Err(()) - } - } + // Don't just leave the child running in the background. + let _ = child.wait(); + + JsonCommandOutput::from_cargo_output(command_out, command_name.to_string()).map_err(|err| { + // Log error, converting it to an `Err(())`. + eprintln!("{err}"); + }) }