]> git.lizzy.rs Git - rust.git/commitdiff
handle error case where --wrapper-version argument doesn't exist
authorDebugSteven <debugsteven@gmail.com>
Sun, 1 Jan 2023 20:20:32 +0000 (13:20 -0700)
committerDebugSteven <debugsteven@gmail.com>
Sun, 1 Jan 2023 20:20:32 +0000 (13:20 -0700)
src/tools/tidy/src/x_version.rs

index dddf72f47471806f8063ffa4b8397756e1547c06..1505775c6cc65f06f9d9b3dba10bd5e8b3bfeb5d 100644 (file)
@@ -4,15 +4,29 @@
 
 pub fn check(bad: &mut bool) {
     let result = Command::new("x").arg("--wrapper-version").stdout(Stdio::piped()).spawn();
-    let child = match result {
-        Ok(child) => child,
-        Err(e) => match e.kind() {
+    // This runs the command inside a temporarily directory.
+    // This allows us to compare output of result to see if `--wrapper-version` is not a recognized argument to x.
+    let temp_result = Command::new("x").arg("--wrapper-version").current_dir(std::env::temp_dir()).stdout(Stdio::piped()).spawn();
+
+    let (child, temp_child) = match (result, temp_result) {
+        (Ok(child), Ok(temp_child)) => (child, temp_child),
+        // what would it mean if the temp cmd error'd?
+        (Ok(_child), Err(_e)) => todo!(),
+        (Err(e), _) => match e.kind() {
             ErrorKind::NotFound => return,
             _ => return tidy_error!(bad, "failed to run `x`: {}", e),
         },
     };
 
     let output = child.wait_with_output().unwrap();
+    let temp_output = temp_child.wait_with_output().unwrap();
+
+    if output != temp_output {
+        return tidy_error!(
+                bad,
+                "Current version of x does not support the `--wrapper-version` argument\nConsider updating to the newer version of x by running `cargo install --path src/tools/x`"
+            )
+    }
 
     if output.status.success() {
         let version = String::from_utf8_lossy(&output.stdout);