Skip to content

Commit

Permalink
Better error message for missing binary
Browse files Browse the repository at this point in the history
  • Loading branch information
In-line committed Jan 20, 2019
1 parent 104c45e commit 04ed1ba
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 5 deletions.
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
65 changes: 65 additions & 0 deletions tests/cli-misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,16 @@ 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 +404,61 @@ 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!("fake_proxy{}", EXE_SUFFIX));
utils::hardlink_file(rustup_path, tool_path).expect("Failed to create fake proxy 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", "fake_proxy"];
expect_err(
config,
broken,
&format!(
"rustup component add fake_proxy{} --toolchain custom-2",
EXE_SUFFIX
),
);

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

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

0 comments on commit 04ed1ba

Please sign in to comment.