-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Changes from 6 commits
8bea1b0
c180eb4
844cde2
a50b10a
dd654d5
3952fdb
81687e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -544,12 +544,31 @@ where | |
let pkg = Box::new(source).download_now(pkgid, config)?; | ||
Ok(pkg) | ||
} | ||
None => bail!( | ||
"could not find `{}` in {} with version `{}`", | ||
dep.package_name(), | ||
source.source_id(), | ||
dep.version_req(), | ||
), | ||
None => { | ||
let version: String = dep.version_req().to_string(); | ||
let pkg_id; | ||
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()); | ||
} | ||
let is_yanked = | ||
pkg_id.map_or(false, |pkg_id| source.is_yanked(pkg_id).unwrap_or(false)); | ||
if is_yanked { | ||
bail!( | ||
"cannot install package `{}`, it has been yanked from {}", | ||
dep.package_name(), | ||
source.source_id() | ||
) | ||
} else { | ||
bail!( | ||
"could not find `{}` in {} with version `{}`", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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. |
||
dep.package_name(), | ||
source.source_id(), | ||
dep.version_req(), | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
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:
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.