Repository: calyxir/calyx (language: rust)

Issue:
[fud2] Improve Error Message When Ninja Doesn't Exist
## Problem
Currently if Ninja isn't installed, a cryptic statement about not finding a file or directory is written. A more permanent solution to this would adding some sort of `fud2 doctor` which would validate dependencies.

This could potentially be very hard if `fud2` were to look at the dependencies of ops as well as it's own dependencies. People (or non-humans too I guess) would have to specify dependencies with an op.

## Proposed Solution 
One would be to validate dependencies for just `fud2` at the beginning of the program. 

But instead of doing that, an easier thing which I think also reasonable is to validate the dependency exists near it's use. In particular, this can be (and probably should have been) built into `ninja_supports_quiet`. 
Edit: It is! I misread the code. The error message should probably be improved though.


Discussion / hints:

Fix patch:
diff --git a/fud2/fud-core/src/run.rs b/fud2/fud-core/src/run.rs
index c30fbdabf1..aa35b8e7d5 100644
--- a/fud2/fud-core/src/run.rs
+++ b/fud2/fud-core/src/run.rs
@@ -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() {
@@ -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 {


Test patch: