Skip to content

Commit

Permalink
[fud2] Improve Error Message When Ninja Is Not Installed (#2255)
Browse files Browse the repository at this point in the history
The error message has been changed from
```
No such file or directory (os error 2)
```
to
```
Error: Unable to run ninja "No such file or directory (os error 2)"
Hint: Is ninja installed correctly?
```

This is intended to close #2254
  • Loading branch information
jku20 authored Aug 8, 2024
1 parent 369e684 commit e283961
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions fud2/fud-core/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ impl<'a> Run<'a> {
}

cmd.stdout(std::io::stderr()); // Send Ninja's stdout to our stderr.
let status = cmd.status()?;
let status = cmd.status().map_err(ninja_cmd_io_error)?;

// Emit to stdout, only when Ninja succeeded.
if status.success() {
Expand Down Expand Up @@ -662,9 +662,26 @@ impl<W: Write> Emitter<W> {
}
}

/// Improve error message of `e` if it is known `e` should be the result of running a `ninja`
/// command.
fn ninja_cmd_io_error(e: std::io::Error) -> std::io::Error {
match e.kind() {
std::io::ErrorKind::NotFound => std::io::Error::new(
e.kind(),
format!(
"Unable to run ninja \"{e}\"\nHint: Is ninja installed correctly?",
),
),
_ => e,
}
}

/// Check whether a Ninja executable supports the `--quiet` flag.
fn ninja_supports_quiet(ninja: &str) -> std::io::Result<bool> {
let version_output = Command::new(ninja).arg("--version").output()?;
let version_output = Command::new(ninja)
.arg("--version")
.output()
.map_err(ninja_cmd_io_error)?;
if let Ok(version) = String::from_utf8(version_output.stdout) {
let parts: Vec<&str> = version.split('.').collect();
if parts.len() >= 2 {
Expand Down

0 comments on commit e283961

Please sign in to comment.