-
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
Add an error when no crates are found from cargo search
#11038
Changes from all commits
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 |
---|---|---|
|
@@ -8,7 +8,7 @@ use std::task::Poll; | |
use std::time::Duration; | ||
use std::{cmp, env}; | ||
|
||
use anyhow::{bail, format_err, Context as _}; | ||
use anyhow::{anyhow, bail, format_err, Context as _}; | ||
use cargo_util::paths; | ||
use crates_io::{self, NewCrate, NewCrateDependency, Registry}; | ||
use curl::easy::{Easy, InfoType, SslOpt, SslVersion}; | ||
|
@@ -984,6 +984,14 @@ pub fn search( | |
) | ||
})?; | ||
|
||
if total_crates == 0 { | ||
return Err(anyhow!( | ||
"could not find any crates matching `{}` from the registry at {}", | ||
query, | ||
registry.host() | ||
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. Normally we elide the registry if its crates.io |
||
)); | ||
} | ||
Comment on lines
+987
to
+993
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. Could you expand on why you feel this behavior change is acceptable? 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. I'm not entirely certain that an error is the correct answer, I mostly did that as it was requested. I think an error might be too harsh since there really wasn't an "error", just no matches. Keeping that in mind, an error is the easiest way to change the output code (1.61.0 does allow That being said, something should probably be shown when no crates were found. Having it output nothing seems like a misstep. 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.
There is also
At least |
||
|
||
let names = crates | ||
.iter() | ||
.map(|krate| format!("{} = \"{}\"", krate.name, krate.max_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.
The motivation for this is scripting but we don't provide any programmatic output which makes me feel like we are providing a false promise by improving scripting support.
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 think the programmatic output is the error code in this case. It should be fairly trivial to check what the code is in most scripting languages.
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 is speculation. I'm concerned that there is also parsing of the output (why do a
cargo search
and only care about the exit code?). We should wait on an actual reply from the reporter