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

Unkind error message failing patch non-existing package with a prerelease version package #12315

Closed
loloicci opened this issue Jun 27, 2023 · 3 comments
Labels
A-dependency-resolution Area: dependency resolution and the resolver A-diagnostics Area: Error and warning messages generated by Cargo itself. A-semver Area: semver specifications, version matching, etc. C-bug Category: bug E-easy Experience: Easy S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review

Comments

@loloicci
Copy link
Contributor

Problem

Trying to patch a stable version package (0.1.0) with prerelease version one (0.1.1-prerelease) fails with an unkind error message if there are no other matching repositories. For example,

root's Cargo.toml:

[package]
name = "cargo-mybin"
version = "0.1.0"
edition = "2021"

[dependencies]
cargo-mylib = "0.1.0"

[patch.crates-io]
cargo-mylib = { git = "https://github.com/loloicci/cargo-mylib.git" }

cargo-mylib's Cargo.toml

[package]
name = "cargo-mylib"
version = "0.1.1-prerelease"
edition = "2021"

cargo update in this cargo-mybin fails with

$ cargo update
    Updating git repository `https://github.com/loloicci/cargo-mylib.git`
    Updating crates.io index
error: no matching package named `cargo-mylib` found
location searched: registry `crates-io`
required by package `cargo-mybin v0.1.0 (/.../cargo-mybin)`

This message says wrong information that no matching package was found. This is because

let all_req = semver::VersionReq::parse("*").unwrap();
let mut new_dep = dep.clone();
new_dep.set_version_req(all_req);
does not match prerelease version.

Steps

  1. clone https://github.com/loloicci/cargo-mybin
  2. execute cargo update on it

Possible Solution(s)

use OptVersionReq::Any instead of semver::VersionReq::parse("*").unwrap() in

let all_req = semver::VersionReq::parse("*").unwrap();
let mut new_dep = dep.clone();
new_dep.set_version_req(all_req);
.

Notes

No response

Version

$ cargo version --verbose
cargo 1.71.0-nightly (09276c703 2023-05-16)
release: 1.71.0-nightly
commit-hash: 09276c703a473ab33daaeb94917232e80eefd628
commit-date: 2023-05-16
host: x86_64-apple-darwin
libgit2: 1.6.4 (sys:0.17.1 vendored)
libcurl: 7.64.1 (sys:0.4.61+curl-8.0.1 system ssl:(SecureTransport) LibreSSL/2.8.3)
ssl: OpenSSL 1.1.1t  7 Feb 2023
os: Mac OS 10.15.7 [64-bit]
@loloicci loloicci added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Jun 27, 2023
loloicci added a commit to loloicci/cargo that referenced this issue Jun 27, 2023
@loloicci
Copy link
Contributor Author

let all_req = semver::VersionReq::parse("*").unwrap();
let mut new_dep = dep.clone();
new_dep.set_version_req(all_req);

is intended and this is used to judge "dependency" specifies the prerelease version package. Using this, printing kind error message for mistakes in "dependency". (see #12316 and its CI fails)

I suggest improving error messages for "patch" specifies prerelease versions.

@Eh2406
Copy link
Contributor

Eh2406 commented Jun 27, 2023

I agree we should use OptVersionReq::Any instead of semver::VersionReq::parse("*").unwrap()!

@weihanglo
Copy link
Member

weihanglo commented Jul 12, 2023

Feel free to hack on this if anyone is interested in it.

@rustbot label -S-triage +S-accepted +A-errors +A-dependency-resolution +A-semver

@rustbot rustbot added A-dependency-resolution Area: dependency resolution and the resolver A-diagnostics Area: Error and warning messages generated by Cargo itself. S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review A-semver Area: semver specifications, version matching, etc. and removed S-triage Status: This issue is waiting on initial triage. labels Jul 12, 2023
@weihanglo weihanglo added the E-easy Experience: Easy label Aug 15, 2023
Eh2406 pushed a commit to Eh2406/cargo that referenced this issue Sep 11, 2023
Eh2406 pushed a commit to Eh2406/cargo that referenced this issue Sep 12, 2023
bors added a commit that referenced this issue Sep 14, 2023
Prerelease candidates error message

### What does this PR try to resolve?

Error messages reporting on versions that do not match the request incorrectly ignore pre-release versions. This is because the version requirement `"*"` cannot match prerelease versions. #12315

### How should we test and review this PR?

Sorry for the large amount of white space changes, fmt got to fmt. 🤷‍♂️

The process was:
- Revise commit from #12316 (thanks to `@loloicci)` that change the requirement from `"*"` to `Any`
- Move the handling of our special "did you mean to specify a pre-release" code and update tests
- some small re-factoring

### Additional information

The old "did you mean to specify a pre-release" #7191 check only occurred when version requirement does not match any versions and you depended on a package that did not have any non-prerelease versions. Making it rarely useful.
The new one will appear any time your version requirement does not match any versions and the package does have pre-release versions. Which may be too common.
I'm open to suggestions for better heuristic.

It's also not clear that the new message make sense in the case of patched versions.
@Eh2406 Eh2406 closed this as completed Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-dependency-resolution Area: dependency resolution and the resolver A-diagnostics Area: Error and warning messages generated by Cargo itself. A-semver Area: semver specifications, version matching, etc. C-bug Category: bug E-easy Experience: Easy S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants