Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c9e6d28

Browse files
committedNov 21, 2018
Give a better error message if a component is not installed
1 parent 1d7fa10 commit c9e6d28

File tree

5 files changed

+40
-16
lines changed

5 files changed

+40
-16
lines changed
 

‎src/rustup-cli/self_update.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use common::{self, Confirm};
3434
use errors::*;
3535
use rustup_dist::dist;
3636
use rustup_utils::utils;
37+
use rustup::{TOOLS, DUP_TOOLS};
3738
use same_file::Handle;
3839
use std::env;
3940
use std::env::consts::EXE_SUFFIX;
@@ -192,14 +193,6 @@ doing then it is fine to continue installation without the build
192193
tools, but otherwise, install the C++ build tools before proceeding.
193194
"#;
194195

195-
static TOOLS: &'static [&'static str] =
196-
&["rustc", "rustdoc", "cargo", "rust-lldb", "rust-gdb", "rls", "cargo-clippy"];
197-
198-
// Tools which are commonly installed by Cargo as well as rustup. We take a bit
199-
// more care with these to ensure we don't overwrite the user's previous
200-
// installation.
201-
static DUP_TOOLS: &'static [&'static str] = &["rustfmt", "cargo-fmt"];
202-
203196
static UPDATE_ROOT: &'static str = "https://static.rust-lang.org/rustup";
204197

205198
/// `CARGO_HOME` suitable for display, possibly with $HOME

‎src/rustup/errors.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use rustup_dist::{self, temp};
22
use rustup_utils;
3+
use component_for_bin;
34
use toml;
45

56
error_chain! {
@@ -27,7 +28,7 @@ error_chain! {
2728
}
2829
BinaryNotFound(t: String, bin: String) {
2930
description("toolchain does not contain binary")
30-
display("toolchain '{}' does not have the binary `{}`", t, bin)
31+
display("'{}' is not installed for the toolchain '{}'{}", bin, t, install_msg(bin))
3132
}
3233
NeedMetadataUpgrade {
3334
description("rustup's metadata is out of date. run `rustup self upgrade-data`")
@@ -71,3 +72,10 @@ error_chain! {
7172
}
7273
}
7374
}
75+
76+
fn install_msg(bin: &str) -> String {
77+
match component_for_bin(bin) {
78+
Some(c) => format!("\nTo install, run `rustup component add {}`", c),
79+
None => String::new(),
80+
}
81+
}

‎src/rustup/lib.rs

+23
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,29 @@ pub use config::*;
2222
pub use toolchain::*;
2323
pub use rustup_utils::{notify, toml_utils, utils};
2424

25+
26+
// A list of all binaries which Rustup will proxy.
27+
pub static TOOLS: &'static [&'static str] =
28+
&["rustc", "rustdoc", "cargo", "rust-lldb", "rust-gdb", "rls", "cargo-clippy"];
29+
30+
// Tools which are commonly installed by Cargo as well as rustup. We take a bit
31+
// more care with these to ensure we don't overwrite the user's previous
32+
// installation.
33+
pub static DUP_TOOLS: &'static [&'static str] = &["rustfmt", "cargo-fmt"];
34+
35+
fn component_for_bin(binary: &str) -> Option<&'static str> {
36+
match binary {
37+
"rustc" | "rustdoc" => Some("rustc"),
38+
"cargo" => Some("cargo"),
39+
"rust-lldb" => Some("lldb-preview"),
40+
"rust-gdb" => Some("gdb-preview"),
41+
"rls" => Some("rls"),
42+
"cargo-clippy" => Some("clippy"),
43+
"rustfmt" | "cargo-fmt" => Some("rustfmt"),
44+
_ => None,
45+
}
46+
}
47+
2548
mod errors;
2649
mod notifications;
2750
mod toolchain;

‎tests/cli-misc.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ fn rustup_failed_path_search() {
377377
config,
378378
broken,
379379
&format!(
380-
"toolchain 'custom' does not have the binary `fake_proxy{}`",
380+
"'fake_proxy{}' is not installed for the toolchain 'custom'",
381381
EXE_SUFFIX
382382
),
383383
);
@@ -550,9 +550,9 @@ fn rls_does_not_exist_in_toolchain() {
550550
config,
551551
&["rls", "--version"],
552552
&format!(
553-
"toolchain 'stable-{}' does not have the binary `rls{}`",
553+
"'rls{}' is not installed for the toolchain 'stable-{}'",
554+
EXE_SUFFIX,
554555
this_host_triple(),
555-
EXE_SUFFIX
556556
),
557557
);
558558
});
@@ -659,12 +659,12 @@ fn rename_rls_remove() {
659659
expect_ok(config, &["rustup", "component", "add", "rls"]);
660660
expect_ok(config, &["rls", "--version"]);
661661
expect_ok(config, &["rustup", "component", "remove", "rls"]);
662-
expect_err(config, &["rls", "--version"], "does not have the binary `rls`");
662+
expect_err(config, &["rls", "--version"], "'rls' is not installed");
663663

664664
expect_ok(config, &["rustup", "component", "add", "rls"]);
665665
expect_ok(config, &["rls", "--version"]);
666666
expect_ok(config, &["rustup", "component", "remove", "rls-preview"]);
667-
expect_err(config, &["rls", "--version"], "does not have the binary `rls`");
667+
expect_err(config, &["rls", "--version"], "'rls' is not installed");
668668
});
669669
}
670670

‎tests/cli-self-upd.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1306,9 +1306,9 @@ fn rls_proxy_set_up_after_install() {
13061306
config,
13071307
&["rls", "--version"],
13081308
&format!(
1309-
"toolchain 'stable-{}' does not have the binary `rls{}`",
1309+
"'rls{}' is not installed for the toolchain 'stable-{}'",
1310+
EXE_SUFFIX,
13101311
this_host_triple(),
1311-
EXE_SUFFIX
13121312
),
13131313
);
13141314
expect_ok(config, &["rustup", "component", "add", "rls"]);

0 commit comments

Comments
 (0)
Please sign in to comment.