-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Improve the error message when running cargo add cubing @v0.5.0
#12331
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
Comments
From the angle of prior art (see #10472)
|
If we supported |
Personally, I think a |
|
It sounds like there are good reasons not to support this, as it could produce other inconsistencies. In that case, I would advocate for the "friendly error message" in the vein that Rust is known for:
|
Just to note: |
|
The tricky part of this error message is that the suggestion “please run: cargo add [email protected]” might not be the correct one. People run with toolchain override If we want this, suggesting |
v
in cargo add
cargo add cubing @v0.5.0
@epage I was having this issue with |
Good point in updating all of them. It would be nice though maybe not required. I am not aware of anyone else working on this. I'd recommend
|
While a version prefixed with a v is not strictly a semantic version it is commonly used, e.g. output by automated release tooling etc, so not supporting it just makes it harder. My philosophy on errors is along the lines of that in the chapter 'Define Errors Out Of Existence' from A Philosophy of Software Design. If the intent is clear I don't see a need on being pedantic. E.g. if I run I would also apply this to |
That is addressing Now, we could make things different between commands. However, this would move us away from a consistency we specifically went to when we added |
Ah okay I see what you mean now, I haven't been doing much Rust the past few years so reread https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#version-requirement-syntax. Personally I think Rust's version requirement syntax is completely unintuitive that is probably why loads of people are confused and asking questions. Yeah maybe accepting |
For |
It would be helpful to cover more cases but we should also be careful to avoid continually extending the scope of the issue such that it makes ti hard to know when its "done". Something that will help is that most commands accept a |
I was wondering if it would it make sense to add an error/help message for just this one case when the package name/version is not checked when As you mentioned, a |
I feel there is a distinction here that I'm missing.
There is not. |
Oh sorry about that. What I meant to say is that
So adding just this one error message to cargo about removing the 'v' from |
So
The 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. |
### What does this PR try to resolve? - Added an error message when version in `CRATE[@<VER>]` or `--version <VER>` starts with 'v' for `install`, `add`, `yank` and `update --precise <VER>` - Check if version is valid in `cargo yank` Fixes #12331 ### How should we test and review this PR? Added tests for each subcommand
This has now been rescoped to providing a good error message if a
v
prefix is present, see #12331 (comment)Problem
I keep doing something the following:
This causes the following error:
I do this because I have a strong habit of prefixing my version numbers with
v
where possible, asvX.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 withv
— to the point that the canonicalcargo
test for for atag
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 ofv
(e.g.npm install [email protected]
), which is an inconsistency that causes a small stumbling block when working with multiple web technologies.Proposed Solution
In order of preference:
v
before a semantic version number.v
and provide a helpful error message that includes something like:If you want to install a specific version, please run: cargo add [email protected]
Notes
No response
The text was updated successfully, but these errors were encountered: