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

Better error message for missing binary #1619

Merged
merged 1 commit into from
Feb 10, 2019
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
14 changes: 10 additions & 4 deletions src/rustup/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ error_chain! {
description("override toolchain is not installed")
display("override toolchain '{}' is not installed", t)
}
BinaryNotFound(t: String, bin: String) {
BinaryNotFound(bin: String, t: String, is_default: bool) {
description("toolchain does not contain binary")
display("'{}' is not installed for the toolchain '{}'{}", bin, t, install_msg(bin))
display("'{}' is not installed for the toolchain '{}'{}", bin, t, install_msg(bin, t, *is_default))
}
NeedMetadataUpgrade {
description("rustup's metadata is out of date. run `rustup self upgrade-data`")
Expand Down Expand Up @@ -73,9 +73,15 @@ error_chain! {
}
}

fn install_msg(bin: &str) -> String {
fn install_msg(bin: &str, toolchain: &str, is_default: bool) -> String {
match component_for_bin(bin) {
Some(c) => format!("\nTo install, run `rustup component add {}`", c),
Some(c) => format!("\nTo install, run `rustup component add {}{}`", c, {
if is_default {
String::new()
} else {
format!(" --toolchain {}", toolchain)
}
}),
None => String::new(),
}
}
3 changes: 2 additions & 1 deletion src/rustup/toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,9 @@ impl<'a> Toolchain<'a> {
.unwrap_or(0);
if recursion_count > env_var::RUST_RECURSION_COUNT_MAX - 1 {
return Err(ErrorKind::BinaryNotFound(
self.name.clone(),
binary.to_string_lossy().into(),
self.name.clone(),
Some(&self.name) == self.cfg.get_default().ok().as_ref(),
)
.into());
}
Expand Down
51 changes: 51 additions & 0 deletions tests/cli-misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,9 @@ fn rustup_failed_path_search() {
&config.customdir.join("custom-1").to_string_lossy(),
],
);

expect_ok(config, &["rustup", "default", "custom"]);

let broken = &["rustup", "run", "custom", "fake_proxy"];
expect_err(
config,
Expand All @@ -394,6 +397,54 @@ fn rustup_failed_path_search() {
});
}

#[test]
fn rustup_failed_path_search_toolchain() {
setup(&|config| {
use std::env::consts::EXE_SUFFIX;

let ref rustup_path = config.exedir.join(&format!("rustup{}", EXE_SUFFIX));
let ref tool_path = config.exedir.join(&format!("cargo-miri{}", EXE_SUFFIX));
utils::hardlink_file(rustup_path, tool_path)
.expect("Failed to create fake cargo-miri for test");

expect_ok(
config,
&[
"rustup",
"toolchain",
"link",
"custom-1",
&config.customdir.join("custom-1").to_string_lossy(),
],
);

expect_ok(
config,
&[
"rustup",
"toolchain",
"link",
"custom-2",
&config.customdir.join("custom-2").to_string_lossy(),
],
);

expect_ok(config, &["rustup", "default", "custom-2"]);

let broken = &["rustup", "run", "custom-1", "cargo-miri"];
expect_err(
config,
broken,
"rustup component add miri --toolchain custom-1",
);

let broken = &["rustup", "run", "custom-2", "cargo-miri"];
expect_err(config, broken, "rustup component add miri");

// Hardlink will be automatically cleaned up by test setup code
});
}

#[test]
fn rustup_run_not_installed() {
setup(&|config| {
Expand Down