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 wrong target names #10982

Closed
ehuss opened this issue Aug 12, 2022 · 1 comment · Fixed by #10999
Closed

Improve error message for wrong target names #10982

ehuss opened this issue Aug 12, 2022 · 1 comment · Fixed by #10999
Labels
A-cargo-targets Area: selection and definition of targets (lib, bins, examples, tests, benches) A-diagnostics Area: Error and warning messages generated by Cargo itself.

Comments

@ehuss
Copy link
Contributor

ehuss commented Aug 12, 2022

If you type the wrong target name, Cargo presents a rather terse error message:

> cargo run --bin foo
error: no bin target named `foo`

If the typo detection works, then it will provide a suggestion; but if it does not, then it doesn't print anything.

It would be helpful if cargo provided a list of valid target names. There are two similar cases where it does that:

> cargo run
error: `cargo run` could not determine which binary to run. Use the `--bin` option to specify a binary, or the `default-run` manifest key.
available binaries: abc, xyz

or

> cargo run --bin
error: "--bin" takes one argument.
Available binaries:
    abc
    xyz

I think the case where the typo detection fails, it should just list all the target names, similar to those two other error messages.

Here is where this code lives.

cargo 1.65.0-nightly (ce40690a5 2022-08-09)
@ehuss ehuss added A-diagnostics Area: Error and warning messages generated by Cargo itself. A-cargo-targets Area: selection and definition of targets (lib, bins, examples, tests, benches) labels Aug 12, 2022
@weihanglo
Copy link
Member

FYI, here is the code printing available targets. It's a bit irksome to make it work peacefully with fn find_named_targets() without poking already lengthy arguments list. When fixing this, we should avoid adding complexity to existing code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cargo-targets Area: selection and definition of targets (lib, bins, examples, tests, benches) A-diagnostics Area: Error and warning messages generated by Cargo itself.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants