cargo: Improve the error message when running `cargo add cubing @v0.5.0`
This has now been rescoped to providing a good error message if a v prefix is present, see https://github.com/rust-lang/cargo/issues/12331#issuecomment-1642551113
Problem
I keep doing something the following:
cargo add cubing@v0.5.0
This causes the following error:
error: invalid version requirement `v0.5.0`
Caused by:
unexpected character 'v' while parsing major version number
I do this because I have a strong habit of prefixing my version numbers with v where possible, as vX.Y.Z tends to be a more unmistakable way to specify a version. And although it is not universal, it is also very common to prefix project release tags with v — to the point that the canonical cargo test for for a tag dependency even uses a value like this: https://github.com/rust-lang/cargo/blob/5b377cece0e0dd0af686cf53ce4637d5d85c2a10/tests/testsuite/cargo_add/git_tag/mod.rs#L22C1-L22C1
(I know that doesn’t have a semantic meaning in this case, but it illustrates how widespread it is to indicate a version using a prefix of v.)
Further, other tools like npm allow a prefix of v (e.g. npm install cubing@v0.38.1), which is an inconsistency that causes a small stumbling block when working with multiple web technologies.
Proposed Solution
In order of preference:
- Accept an extra
vbefore a semantic version number. - Recognize the extra
vand provide a helpful error message that includes something like:If you want to install a specific version, please run: cargo add cubing@0.5.0
Notes
No response
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 20 (14 by maintainers)
So
cargo yankhas the following failure modes which talk to the registryThe API spec says those should be crate names and versions. I’m fine with validating the version. I wouldn’t bother verifying unknown versions or names as we’ll just have to talk to the registry to check that and we might as well do that in one call.
@latestis being discussed at #10741Personally, I think a
vbeing supported forcargo addwould be incorrect.cargo addaccepts a version requirement and not a version and we would not want to confuse that further by having a “sigil” that implies its a version. For the other commands, there would be more room for consideration with the drawback that it would make the commands more consistent in accepted syntax while adding support for@in all commands was a drive for consistency (#10582).From the angle of prior art (see #10472)
npmandgosupport a leadingvpoetry,yarn,pnpm,bundle, andpubdo not