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

Improve error message for no such subcommand #10900

Closed
CAD97 opened this issue Jul 25, 2022 · 4 comments · Fixed by #10924
Closed

Improve error message for no such subcommand #10900

CAD97 opened this issue Jul 25, 2022 · 4 comments · Fixed by #10924
Assignees
Labels
A-diagnostics Area: Error and warning messages generated by Cargo itself. A-rustup Area: rustup interaction C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` E-easy Experience: Easy

Comments

@CAD97
Copy link
Contributor

CAD97 commented Jul 25, 2022

Problem

With the rustup changes to set $RUSTC et al, it's become more likely that people will accidentally use +toolchain on cargo/rustc/etc directly rather than through the rustup shims. While we shouldn't try to handle the toolchain flag ourselves, it would be beneficial to recognize it in the "no such subcommand" path and print a help note notifying the user that cargo received the +toolchain argument but can't handle it.

〉main:pegcel〉rustup which cargo
D:\.rust\rustup\toolchains\stable-x86_64-pc-windows-msvc\bin\cargo.exe
〉main:pegcel〉D:\.rust\rustup\toolchains\stable-x86_64-pc-windows-msvc\bin\cargo.exe +nightly check
error: no such subcommand: `+nightly`

Proposed Solution

〉main:pegcel〉rustup which cargo
D:\.rust\rustup\toolchains\stable-x86_64-pc-windows-msvc\bin\cargo.exe
〉main:pegcel〉D:\.rust\rustup\toolchains\stable-x86_64-pc-windows-msvc\bin\cargo.exe +nightly check
error: no such subcommand: `+nightly`

        Did you mean to run cargo through rustup?
        Cargo does not handle `+toolchain` directives itself.

Notes

Some rustup context:

@CAD97 CAD97 added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Jul 25, 2022
@ehuss
Copy link
Contributor

ehuss commented Jul 25, 2022

Thanks for the suggestion! This is essentially a duplicate of #9652. However, since this has more detail I'll close the other issue. However, #9652 contains a few different experience reports.

@ehuss ehuss added A-diagnostics Area: Error and warning messages generated by Cargo itself. A-rustup Area: rustup interaction labels Jul 25, 2022
@CAD97
Copy link
Contributor Author

CAD97 commented Jul 25, 2022

The change should IIUC slot in right here:

cargo/src/bin/cargo/main.rs

Lines 164 to 174 in 85b500c

fn execute_external_subcommand(config: &Config, cmd: &str, args: &[&str]) -> CliResult {
let path = find_external_subcommand(config, cmd);
let command = match path {
Some(command) => command,
None => {
let suggestions = list_commands(config);
let did_you_mean = closest_msg(cmd, suggestions.keys(), |c| c);
let err = anyhow::format_err!("no such subcommand: `{}`{}", cmd, did_you_mean);
return Err(CliError::new(err, 101));
}
};

@ehuss ehuss added the E-easy Experience: Easy label Jul 30, 2022
@ehuss ehuss changed the title On unrecognized subcommand, check if it looks like +toolchain and print a note Improve error message for no such subcommand Jul 30, 2022
@ehuss
Copy link
Contributor

ehuss commented Jul 30, 2022

Another thought I had that would be useful (unrelated to +toolchain) is to also print a note, recommending the user run cargo --list to get a complete list of subcommands. Otherwise the error can be a bit terse:

> cargo cargo
error: no such subcommand: `cargo`

@bindsdev
Copy link
Contributor

bindsdev commented Aug 2, 2022

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Error and warning messages generated by Cargo itself. A-rustup Area: rustup interaction C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` E-easy Experience: Easy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants