Skip to content

Commit 2c0cd97

Browse files
committed
Simplify error handling.
1 parent afa3ace commit 2c0cd97

File tree

1 file changed

+27
-34
lines changed

1 file changed

+27
-34
lines changed

src/cargo/core/registry.rs

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -774,17 +774,14 @@ fn summary_for_patch(
774774
// No summaries found, try to help the user figure out what is wrong.
775775
if let Some((locked_patch, locked_id)) = locked {
776776
// Since the locked patch did not match anything, try the unlocked one.
777-
let mut orig_matches = match source.query_vec(orig_patch) {
778-
Ok(summaries) => summaries,
779-
Err(e) => {
780-
log::warn!(
781-
"could not determine unlocked summaries for dep {:?}: {:?}",
782-
orig_patch,
783-
e
784-
);
785-
Vec::new()
786-
}
787-
};
777+
let mut orig_matches = source.query_vec(orig_patch).unwrap_or_else(|e| {
778+
log::warn!(
779+
"could not determine unlocked summaries for dep {:?}: {:?}",
780+
orig_patch,
781+
e
782+
);
783+
Vec::new()
784+
});
788785
if orig_matches.is_empty() {
789786
// This should be relatively unusual. For example, a patch of
790787
// {version="0.1.2", ...} and the patch location no longer contains a
@@ -810,29 +807,25 @@ fn summary_for_patch(
810807
// Try checking if there are *any* packages that match this by name.
811808
let name_only_dep =
812809
Dependency::new_override(orig_patch.package_name(), orig_patch.source_id());
813-
let found = match source.query_vec(&name_only_dep) {
814-
Ok(name_summaries) => {
815-
let mut vers = name_summaries
816-
.iter()
817-
.map(|summary| summary.version())
818-
.collect::<Vec<_>>();
819-
match vers.len() {
820-
0 => format!(""),
821-
1 => format!("version `{}`", vers[0]),
822-
_ => {
823-
vers.sort();
824-
let strs: Vec<_> = vers.into_iter().map(|v| v.to_string()).collect();
825-
format!("versions `{}`", strs.join(", "))
826-
}
827-
}
828-
}
829-
Err(e) => {
830-
log::warn!(
831-
"failed to do name-only summary query for {:?}: {:?}",
832-
name_only_dep,
833-
e
834-
);
835-
"".to_string()
810+
let name_summaries = source.query_vec(&name_only_dep).unwrap_or_else(|e| {
811+
log::warn!(
812+
"failed to do name-only summary query for {:?}: {:?}",
813+
name_only_dep,
814+
e
815+
);
816+
Vec::new()
817+
});
818+
let mut vers = name_summaries
819+
.iter()
820+
.map(|summary| summary.version())
821+
.collect::<Vec<_>>();
822+
let found = match vers.len() {
823+
0 => format!(""),
824+
1 => format!("version `{}`", vers[0]),
825+
_ => {
826+
vers.sort();
827+
let strs: Vec<_> = vers.into_iter().map(|v| v.to_string()).collect();
828+
format!("versions `{}`", strs.join(", "))
836829
}
837830
};
838831
if found.is_empty() {

0 commit comments

Comments
 (0)