Skip to content

Commit

Permalink
report error when rustup is invoked with unsupported arg0
Browse files Browse the repository at this point in the history
Better error
  • Loading branch information
Rustin170506 committed Apr 12, 2021
1 parent b132a85 commit 46a7a06
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
9 changes: 8 additions & 1 deletion src/bin/rustup-init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use rustup::cli::setup_mode;
use rustup::currentprocess::{process, with, OSProcess};
use rustup::env_var::RUST_RECURSION_COUNT_MAX;
use rustup::utils::utils;
use rustup::TOOLS;

fn main() {
let process = OSProcess::default();
Expand Down Expand Up @@ -93,7 +94,13 @@ fn run_rustup_inner() -> Result<utils::ExitCode> {
}
}
}
Some(_) => proxy_mode::main(),
Some(n) => {
if TOOLS.iter().find(|&&name| name == n).is_some() {
proxy_mode::main()
} else {
Err(ErrorKind::UnknownProxyName(n.to_string()).into())
}
}
None => {
// Weird case. No arg0, or it's unparsable.
Err(ErrorKind::NoExeName.into())
Expand Down
17 changes: 17 additions & 0 deletions src/cli/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use strsim::damerau_levenshtein;

use super::rustup_mode::CompletionCommand;
use crate::dist::temp;
use crate::TOOLS;

error_chain! {
links {
Expand Down Expand Up @@ -47,6 +48,14 @@ error_chain! {
NoExeName {
description("couldn't determine self executable name")
}
UnknownProxyName(n: String) {
description("unknown proxy name")
display(
"unknown proxy name: '{}'; valid profile names are {}",
n,
valid_proxy_names(),
)
}
NotSelfInstalled(p: PathBuf) {
description("rustup is not installed")
display("rustup is not installed at '{}'", p.display())
Expand Down Expand Up @@ -74,6 +83,14 @@ error_chain! {
}
}

fn valid_proxy_names() -> String {
TOOLS
.iter()
.map(|s| format!("'{}'", s))
.collect::<Vec<_>>()
.join(", ")
}

fn maybe_suggest_toolchain(bad_name: &str) -> String {
let bad_name = &bad_name.to_ascii_lowercase();
static VALID_CHANNELS: &[&str] = &["stable", "beta", "nightly"];
Expand Down
5 changes: 1 addition & 4 deletions tests/cli-misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,7 @@ fn rustup_failed_path_search() {
expect_err(
config,
broken,
&format!(
"'fake_proxy{}' is not installed for the toolchain 'custom'",
EXE_SUFFIX
),
&format!("unknown proxy name: 'fake_proxy'; valid profile names are 'rustc', 'rustdoc', 'cargo', 'rust-lldb', 'rust-gdb', 'rls', 'cargo-clippy', 'clippy-driver', 'cargo-miri'",),
);

// Hardlink will be automatically cleaned up by test setup code
Expand Down

0 comments on commit 46a7a06

Please sign in to comment.