Skip to content

Commit 6d3d46b

Browse files
committed
Auto merge of #1128 - shiver:issue-820, r=Diggsey
#820 Supress confusing NotADirectory error and show override missing This is my attempt at tackling issue #820. Hopefully I interpreted the original request correctly and this is what you were looking for. It is my first time dealing with error_chain, so not 100% sure I did it right. Any suggestions you might have to improve the submission would be great. Thanks!
2 parents 0efe0bb + 1f27bbf commit 6d3d46b

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

src/rustup/config.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,18 @@ impl Cfg {
233233
Ok(s.find_override(path, self.notify_handler.as_ref()))
234234
}));
235235
if let Some((name, reason_path)) = result {
236-
let toolchain = try!(self.verify_toolchain(&name).chain_err(|| ErrorKind::ToolchainNotInstalled(name.to_string())));
236+
let toolchain = match self.verify_toolchain(&name) {
237+
Ok(t) => { t },
238+
Err(Error(ErrorKind::Utils(::rustup_utils::ErrorKind::NotADirectory { .. }), _)) => {
239+
// Strip the confusing NotADirectory error and only mention that the override
240+
// toolchain is not installed.
241+
return Err(ErrorKind::OverrideToolchainNotInstalled(name.to_string()).into())
242+
},
243+
Err(e) => return Err(e).chain_err(|| {
244+
ErrorKind::OverrideToolchainNotInstalled(name.to_string())
245+
})
246+
247+
};
237248
return Ok(Some((toolchain, OverrideReason::OverrideDB(reason_path))));
238249
}
239250

src/rustup/errors.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ error_chain! {
2222
description("toolchain is not installed")
2323
display("toolchain '{}' is not installed", t)
2424
}
25+
OverrideToolchainNotInstalled(t: String) {
26+
description("override toolchain is not installed")
27+
display("override toolchain '{}' is not installed", t)
28+
}
2529
BinaryNotFound(t: String, bin: String) {
2630
description("toolchain does not contain binary")
2731
display("toolchain '{}' does not have the binary `{}`", t, bin)

tests/cli-rustup.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,14 @@ fn show_toolchain_override_not_installed() {
512512
expect_ok(config, &["rustup", "toolchain", "remove", "nightly"]);
513513
// I'm not sure this should really be erroring when the toolchain
514514
// is not installed; just capturing the behavior.
515-
expect_err(config, &["rustup", "show"],
516-
for_host!(r"error: toolchain 'nightly-{0}' is not installed"));
515+
let mut cmd = clitools::cmd(config, "rustup", &["show"]);
516+
clitools::env(config, &mut cmd);
517+
let out = cmd.output().unwrap();
518+
assert!(!out.status.success());
519+
let stderr = String::from_utf8(out.stderr).unwrap();
520+
assert!(stderr.starts_with(
521+
for_host!("error: override toolchain 'nightly-{0}' is not installed")));
522+
assert!(!stderr.contains("info: caused by: not a directory: "));
517523
});
518524
}
519525

0 commit comments

Comments
 (0)