Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#820 Supress confusing NotADirectory error and show override missing #1128

Merged
merged 2 commits into from
May 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/rustup/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,18 @@ impl Cfg {
Ok(s.find_override(path, self.notify_handler.as_ref()))
}));
if let Some((name, reason_path)) = result {
let toolchain = try!(self.verify_toolchain(&name).chain_err(|| ErrorKind::ToolchainNotInstalled(name.to_string())));
let toolchain = match self.verify_toolchain(&name) {
Ok(t) => { t },
Err(Error(ErrorKind::Utils(::rustup_utils::ErrorKind::NotADirectory { .. }), _)) => {
// Strip the confusing NotADirectory error and only mention that the override
// toolchain is not installed.
return Err(ErrorKind::OverrideToolchainNotInstalled(name.to_string()).into())
},
Err(e) => return Err(e).chain_err(|| {
ErrorKind::OverrideToolchainNotInstalled(name.to_string())
})

};
return Ok(Some((toolchain, OverrideReason::OverrideDB(reason_path))));
}

Expand Down
4 changes: 4 additions & 0 deletions src/rustup/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ error_chain! {
description("toolchain is not installed")
display("toolchain '{}' is not installed", t)
}
OverrideToolchainNotInstalled(t: String) {
description("override toolchain is not installed")
display("override toolchain '{}' is not installed", t)
}
BinaryNotFound(t: String, bin: String) {
description("toolchain does not contain binary")
display("toolchain '{}' does not have the binary `{}`", t, bin)
Expand Down
10 changes: 8 additions & 2 deletions tests/cli-rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,14 @@ fn show_toolchain_override_not_installed() {
expect_ok(config, &["rustup", "toolchain", "remove", "nightly"]);
// I'm not sure this should really be erroring when the toolchain
// is not installed; just capturing the behavior.
expect_err(config, &["rustup", "show"],
for_host!(r"error: toolchain 'nightly-{0}' is not installed"));
let mut cmd = clitools::cmd(config, "rustup", &["show"]);
clitools::env(config, &mut cmd);
let out = cmd.output().unwrap();
assert!(!out.status.success());
let stderr = String::from_utf8(out.stderr).unwrap();
assert!(stderr.starts_with(
for_host!("error: override toolchain 'nightly-{0}' is not installed")));
assert!(!stderr.contains("info: caused by: not a directory: "));
});
}

Expand Down