Skip to content

Commit

Permalink
update error message
Browse files Browse the repository at this point in the history
  • Loading branch information
ValeryAntopol committed Jun 5, 2024
1 parent fb6b07d commit b0f792e
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions tools/cli/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

use std::fmt::Formatter;
use std::io::ErrorKind;
use std::process::Command;
use std::process::Stdio;

Expand All @@ -33,18 +34,15 @@ fn run_command<T: Into<Stdio>>(
mut command: Command,
stdout_config: T,
) -> Result<String, anyhow::Error> {
let process = command.stdout(stdout_config).spawn().map_err(|e| {
anyhow::anyhow!(
r#"cannot run "{}": {}"#,
command.get_program().to_string_lossy(),
e
)
})?;
let process = command
.stdout(stdout_config)
.spawn()
.map_err(|e| process_command_run_error(e, &command))?;

let output = process.wait_with_output()?;
if !output.status.success() {
anyhow::bail!(
r#"command "{}" exited with {}"#,
r#"command `{}` exited with {}"#,
PrintCommand(&command),
output.status
)
Expand All @@ -66,3 +64,18 @@ impl<'c> std::fmt::Display for PrintCommand<'c> {
Ok(())
}
}

fn process_command_run_error(e: std::io::Error, command: &Command) -> anyhow::Error {
if e.kind() == ErrorKind::NotFound {
anyhow::anyhow!(
r#"cannot run `{}`: executable not found in $PATH"#,
command.get_program().to_string_lossy(),
)
} else {
anyhow::anyhow!(
r#"cannot run `{}`: {}"#,
command.get_program().to_string_lossy(),
e
)
}
}

0 comments on commit b0f792e

Please sign in to comment.