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

cargo install with specific yanked version gives confusing "not found" error #8565

Merged
merged 7 commits into from
Aug 5, 2020

Conversation

pawanbisht62
Copy link

Resolves #8171

@rust-highfive
Copy link

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.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 30, 2020
@pawanbisht62 pawanbisht62 changed the title cargo install with specific yanked version gives confusing "not found" error [WIP] cargo install with specific yanked version gives confusing "not found" error Jul 30, 2020
@pawanbisht62 pawanbisht62 changed the title [WIP] cargo install with specific yanked version gives confusing "not found" error cargo install with specific yanked version gives confusing "not found" error Jul 31, 2020
Copy link
Contributor

@ehuss ehuss left a 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())
Copy link
Contributor

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 {}

Copy link
Author

@pawanbisht62 pawanbisht62 Jul 31, 2020

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.

@ehuss
Copy link
Contributor

ehuss commented Jul 31, 2020

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 simple test up top is a good, basic example.

Essentially it needs to call Package::new to create a new package in the registry, and call yanked to set its yanked status.

Then call cargo_process("install foo") and check that it fails with_status(101) and that check the output using with_stderr("...").

@bishtpawan
Copy link
Contributor

Hi @ehuss,I've updated the PR by updating the code and also added one new test-case.
Can you please have a look at the CI/test the failed one. I'm unable to get details like why 2 tests are failing. Thanks

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`")
Copy link
Contributor

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.

Copy link
Contributor

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.

[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`",
Copy link
Contributor

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.

Copy link
Contributor

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()) {
Copy link
Contributor

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 `{}`",
Copy link
Contributor

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
}

Copy link
Contributor

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.

@ehuss
Copy link
Contributor

ehuss commented Aug 3, 2020

Can you please have a look at the CI/test the failed one. I'm unable to get details like why 2 tests are failing. Thanks

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.

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());
Copy link
Contributor

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
};

Copy link
Contributor

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.

@ehuss
Copy link
Contributor

ehuss commented Aug 5, 2020

Thanks! And thanks for putting up with my pickiness. 😄

@bors r+

@bors
Copy link
Contributor

bors commented Aug 5, 2020

📌 Commit 81687e7 has been approved by ehuss

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 5, 2020
@bors
Copy link
Contributor

bors commented Aug 5, 2020

⌛ Testing commit 81687e7 with merge 0aedda2...

@bors
Copy link
Contributor

bors commented Aug 5, 2020

☀️ Test successful - checks-actions
Approved by: ehuss
Pushing 0aedda2 to master...

@bors bors merged commit 0aedda2 into rust-lang:master Aug 5, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Aug 13, 2020
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)
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 13, 2020
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)
@ehuss ehuss added this to the 1.47.0 milestone Feb 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cargo install with specific yanked version gives confusing "not found" error
5 participants