-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
cargo install with specific yanked version gives confusing "not found" error #8565
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @ehuss (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Looks like this needs a test. Let me know if you need any help writing one.
None => { | ||
for pkg_id in deps.iter() { | ||
if source.is_yanked(pkg_id.package_id()).unwrap_or(false) { | ||
bail!("provided package has been yanked `{}`", pkg_id.package_id()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a small note on the wording, perhaps it could be written as:
cannot install package `{}`, it has been yanked from {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @ehuss for suggestion, I'll definitely update the message and can you please specify the value for the second placeholder here? I mean yanked from what? Correct me if I'm wrong, here you mean the package name and for first place holder the specific version of package right?
And regarding test it would be helpful, if you guide me to add test for this.
For Cargo's testsuite, there is some high-level documentation in https://github.com/rust-lang/cargo/blob/master/CONTRIBUTING.md#running-tests for running tests. See https://github.com/rust-lang/cargo/blob/master/crates/cargo-test-support/src/lib.rs for an introduction to writing tests. The test should probably go in https://github.com/rust-lang/cargo/blob/master/tests/testsuite/install.rs. There are a bunch of other tests in there that you can look at for examples. The Essentially it needs to call Then call |
4c20b3b
to
faf3ca5
Compare
Hi @ehuss,I've updated the PR by updating the code and also added one new test-case. |
tests/testsuite/install.rs
Outdated
Package::new("baz", "0.0.1").yanked(true).publish(); | ||
cargo_process("install baz --version 0.0.1") | ||
.with_status(101) | ||
.with_stderr_contains("error: cannot install package `baz`, it has been yanked from registry `https://github.com/rust-lang/crates.io-index`") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you split up this line so it is less than 100 characters long? Just add some \
characters to split the string across a few lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion. I've updated the PR, please have a look.
tests/testsuite/install_upgrade.rs
Outdated
[ERROR] could not find `foo` in registry `[..]` with version `=1.0.1` | ||
", | ||
.with_stderr_contains( | ||
"error: cannot install package `foo`, it has been yanked from registry `https://github.com/rust-lang/crates.io-index`", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This string could be split up, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion. I've updated the PR, please have a look.
), | ||
None => { | ||
let version: String = dep.version_req().to_string(); | ||
match PackageId::new(dep.package_name(), &version[1..], source.source_id()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little uncomfortable just blindly stripping the first character from the version req. Perhaps only do the check if version_req().is_exact()
? I think that should guarantee that it is =
followed by an exact version.
Which reminds me that this doesn't help for non-specific versions (like *
or ~2
). That's probably a bigger can of worms, though.
} | ||
} | ||
Err(_) => bail!( | ||
"could not find `{}` in {} with version `{}`", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be restructured to avoid the duplication of these two cases? Maybe something like:
let maybe_pkg_id = PackageId::new(dep.package_name(), &version[1..], source.source_id());
let is_yanked = maybe_pkg_id.map_or(false, |pkg_id| source.is_yanked(pkg_id).unwrap_or(false));
if is_yanked {
// ...yanked error
} else {
// ...not found error
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are correct. Thanks for the snippet. I've incorporated this in the PR. Please have a look once you get time.
This was just something that changed in nightly, it should be fixed now (via #8576). If you rebase on the latest master, it should be fixed. |
e8d8a5a
to
538fd80
Compare
if dep.version_req().is_exact() { | ||
pkg_id = PackageId::new(dep.package_name(), &version[1..], source.source_id()); | ||
} else { | ||
pkg_id = PackageId::new(dep.package_name(), &version[..], source.source_id()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this line is almost guaranteed to fail, I think it is a little misleading to try to create the PackageId here. Maybe be a little more explicit here? For example, something like the following:
let is_yanked = if dep.version_req().is_exact() {
let version: String = dep.version_req().to_string();
PackageId::new(dep.package_name(), &version[1..], source.source_id())
.map_or(false, |pkg_id| source.is_yanked(pkg_id).unwrap_or(false))
} else {
false
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay got it, like if we don't have exact version then control will always go to the else part. Let me update the PR. Thanks again for explaining your point with the code snippet, which really helps me to get your point.
Thanks! And thanks for putting up with my pickiness. 😄 @bors r+ |
📌 Commit 81687e7 has been approved by |
☀️ Test successful - checks-actions |
Update cargo 7 commits in 1653f354644834073d6d2541e27fae94588e685e..ab32ee88dade1b50c77347599e82ca2de3fb8a51 2020-08-04 23:14:37 +0000 to 2020-08-10 17:44:43 +0000 - Build manpage archive deterministically (rust-lang/cargo#8600) - doc: Qualify GNU licenses in example license field (rust-lang/cargo#8604) - Fix jobserver_exists test on single-cpu systems (rust-lang/cargo#8598) - Fix small typo in reference/profiles.md (rust-lang/cargo#8605) - Default cargo publish to the alt registry if it's the only allowed one (rust-lang/cargo#8571) - cargo install with specific yanked version gives confusing "not found" error (rust-lang/cargo#8565) - Fix typo (rust-lang/cargo#8589)
Update cargo 7 commits in 1653f354644834073d6d2541e27fae94588e685e..ab32ee88dade1b50c77347599e82ca2de3fb8a51 2020-08-04 23:14:37 +0000 to 2020-08-10 17:44:43 +0000 - Build manpage archive deterministically (rust-lang/cargo#8600) - doc: Qualify GNU licenses in example license field (rust-lang/cargo#8604) - Fix jobserver_exists test on single-cpu systems (rust-lang/cargo#8598) - Fix small typo in reference/profiles.md (rust-lang/cargo#8605) - Default cargo publish to the alt registry if it's the only allowed one (rust-lang/cargo#8571) - cargo install with specific yanked version gives confusing "not found" error (rust-lang/cargo#8565) - Fix typo (rust-lang/cargo#8589)
Resolves #8171