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

Better error report when crate name is empty #13314

Closed
orowith2os opened this issue Jan 17, 2024 · 2 comments
Closed

Better error report when crate name is empty #13314

orowith2os opened this issue Jan 17, 2024 · 2 comments
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-triage Status: This issue is waiting on initial triage.

Comments

@orowith2os
Copy link

Problem

When adding a crate via cargo add, if one adds a space before the version (such that it's cargo add chumsky @1.0.0-alpha.6 instead of cargo add [email protected] ), Cargo will panic with the following failed assertion:

    Updating crates.io index
thread 'main' panicked at src/cargo/core/dependency.rs:164:9:
assertion failed: !name.is_empty()
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Proposed Solution

When the crate name to add is empty, print a nicer error instead.

Notes

Here's another potentially interesting output to look at:

oro@CrystalBox /r/m/o/V/vala-thingy (master)> cargo add chumsky@ 1.0.0-alpha.6
error: invalid version requirement ``

Caused by:
  unexpected end of input while parsing major version number
@orowith2os orowith2os added C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-triage Status: This issue is waiting on initial triage. labels Jan 17, 2024
@epage
Copy link
Contributor

epage commented Jan 17, 2024

The panic has since been fixed (either #13164 or #13152). Using nightly, I get

error: package name cannot be empty

It could be interesting to explore what are common cases that we can detect and provide better suggestions. For example, as the person who merged cargo add into cargo (ie I should know better), I recently did something like cargo add winnow 0.5.13 (this started as a friendly jab about chumsky but I think it honestly was with winnow).

@orowith2os
Copy link
Author

Maybe it would be feasible to detect a version tag, on its own, and suggest merging it with a crate without a version tag?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

No branches or pull requests

2 participants