Skip to content

Commit 5e58a18

Browse files
committed
report error when rustup is invoked with unsupported arg0
Better error fix typo
1 parent b132a85 commit 5e58a18

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

src/bin/rustup-init.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use rustup::cli::setup_mode;
2929
use rustup::currentprocess::{process, with, OSProcess};
3030
use rustup::env_var::RUST_RECURSION_COUNT_MAX;
3131
use rustup::utils::utils;
32+
use rustup::TOOLS;
3233

3334
fn main() {
3435
let process = OSProcess::default();
@@ -93,7 +94,13 @@ fn run_rustup_inner() -> Result<utils::ExitCode> {
9394
}
9495
}
9596
}
96-
Some(_) => proxy_mode::main(),
97+
Some(n) => {
98+
if TOOLS.iter().find(|&&name| name == n).is_some() {
99+
proxy_mode::main()
100+
} else {
101+
Err(ErrorKind::UnknownProxyName(n.to_string()).into())
102+
}
103+
}
97104
None => {
98105
// Weird case. No arg0, or it's unparsable.
99106
Err(ErrorKind::NoExeName.into())

src/cli/errors.rs

+17
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use strsim::damerau_levenshtein;
1313

1414
use super::rustup_mode::CompletionCommand;
1515
use crate::dist::temp;
16+
use crate::TOOLS;
1617

1718
error_chain! {
1819
links {
@@ -47,6 +48,14 @@ error_chain! {
4748
NoExeName {
4849
description("couldn't determine self executable name")
4950
}
51+
UnknownProxyName(n: String) {
52+
description("unknown proxy name")
53+
display(
54+
"unknown proxy name: '{}'; valid proxy names are {}",
55+
n,
56+
valid_proxy_names(),
57+
)
58+
}
5059
NotSelfInstalled(p: PathBuf) {
5160
description("rustup is not installed")
5261
display("rustup is not installed at '{}'", p.display())
@@ -74,6 +83,14 @@ error_chain! {
7483
}
7584
}
7685

86+
fn valid_proxy_names() -> String {
87+
TOOLS
88+
.iter()
89+
.map(|s| format!("'{}'", s))
90+
.collect::<Vec<_>>()
91+
.join(", ")
92+
}
93+
7794
fn maybe_suggest_toolchain(bad_name: &str) -> String {
7895
let bad_name = &bad_name.to_ascii_lowercase();
7996
static VALID_CHANNELS: &[&str] = &["stable", "beta", "nightly"];

tests/cli-misc.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,7 @@ fn rustup_failed_path_search() {
325325
expect_err(
326326
config,
327327
broken,
328-
&format!(
329-
"'fake_proxy{}' is not installed for the toolchain 'custom'",
330-
EXE_SUFFIX
331-
),
328+
&format!("unknown proxy name: 'fake_proxy'; valid proxy names are 'rustc', 'rustdoc', 'cargo', 'rust-lldb', 'rust-gdb', 'rls', 'cargo-clippy', 'clippy-driver', 'cargo-miri'",),
332329
);
333330

334331
// Hardlink will be automatically cleaned up by test setup code

0 commit comments

Comments
 (0)