Skip to content

Commit 5e67ce6

Browse files
committed
handle error case where --wrapper-version argument doesn't exist
1 parent f50ad6c commit 5e67ce6

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/tools/tidy/src/x_version.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,29 @@ use std::process::{Command, Stdio};
44

55
pub fn check(bad: &mut bool) {
66
let result = Command::new("x").arg("--wrapper-version").stdout(Stdio::piped()).spawn();
7-
let child = match result {
8-
Ok(child) => child,
9-
Err(e) => match e.kind() {
7+
// This runs the command inside a temporarily directory.
8+
// This allows us to compare output of result to see if `--wrapper-version` is not a recognized argument to x.
9+
let temp_result = Command::new("x").arg("--wrapper-version").current_dir(std::env::temp_dir()).stdout(Stdio::piped()).spawn();
10+
11+
let (child, temp_child) = match (result, temp_result) {
12+
(Ok(child), Ok(temp_child)) => (child, temp_child),
13+
// what would it mean if the temp cmd error'd?
14+
(Ok(_child), Err(_e)) => todo!(),
15+
(Err(e), _) => match e.kind() {
1016
ErrorKind::NotFound => return,
1117
_ => return tidy_error!(bad, "failed to run `x`: {}", e),
1218
},
1319
};
1420

1521
let output = child.wait_with_output().unwrap();
22+
let temp_output = temp_child.wait_with_output().unwrap();
23+
24+
if output != temp_output {
25+
return tidy_error!(
26+
bad,
27+
"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`"
28+
)
29+
}
1630

1731
if output.status.success() {
1832
let version = String::from_utf8_lossy(&output.stdout);

0 commit comments

Comments
 (0)