Skip to content

Commit 0f27d6e

Browse files
committed
Remove indirection in update error handling
1 parent e230748 commit 0f27d6e

File tree

1 file changed

+20
-41
lines changed

1 file changed

+20
-41
lines changed

src/dist/mod.rs

Lines changed: 20 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,60 +1001,39 @@ async fn try_update_from_dist_(
10011001
};
10021002
}
10031003
Ok(None) => return Ok(None),
1004-
Err(any) => {
1005-
enum Cases {
1006-
DNE,
1007-
CF,
1008-
Other,
1009-
}
1010-
let case = match any.downcast_ref::<RustupError>() {
1011-
Some(RustupError::ChecksumFailed { .. }) => Cases::CF,
1012-
Some(RustupError::DownloadNotExists { .. }) => Cases::DNE,
1013-
_ => Cases::Other,
1014-
};
1015-
match case {
1016-
Cases::CF => return Ok(None),
1017-
Cases::DNE => {
1004+
Err(err) => {
1005+
match err.downcast_ref::<RustupError>() {
1006+
Some(RustupError::ChecksumFailed { .. }) => return Ok(None),
1007+
Some(RustupError::DownloadNotExists { .. }) => {
10181008
// Proceed to try v1 as a fallback
1019-
(download.notify_handler)(Notification::DownloadingLegacyManifest);
1009+
(download.notify_handler)(Notification::DownloadingLegacyManifest)
10201010
}
1021-
Cases::Other => return Err(any),
1011+
_ => return Err(err),
10221012
}
10231013
}
10241014
}
10251015

10261016
// If the v2 manifest is not found then try v1
10271017
let manifest = match dl_v1_manifest(download, toolchain).await {
10281018
Ok(m) => m,
1029-
Err(any) => {
1030-
enum Cases {
1031-
DNE,
1032-
CF,
1033-
Other,
1019+
Err(err) => match err.downcast_ref::<RustupError>() {
1020+
Some(RustupError::ChecksumFailed { .. }) => return Err(err),
1021+
Some(RustupError::DownloadNotExists { .. }) => {
1022+
bail!(DistError::MissingReleaseForToolchain(
1023+
toolchain.manifest_name()
1024+
));
10341025
}
1035-
let case = match any.downcast_ref::<RustupError>() {
1036-
Some(RustupError::ChecksumFailed { .. }) => Cases::CF,
1037-
Some(RustupError::DownloadNotExists { .. }) => Cases::DNE,
1038-
_ => Cases::Other,
1039-
};
1040-
match case {
1041-
Cases::DNE => {
1042-
bail!(DistError::MissingReleaseForToolchain(
1026+
_ => {
1027+
return Err(err).with_context(|| {
1028+
format!(
1029+
"failed to download manifest for '{}'",
10431030
toolchain.manifest_name()
1044-
));
1045-
}
1046-
Cases::CF => return Err(any),
1047-
Cases::Other => {
1048-
return Err(any).with_context(|| {
1049-
format!(
1050-
"failed to download manifest for '{}'",
1051-
toolchain.manifest_name()
1052-
)
1053-
});
1054-
}
1031+
)
1032+
});
10551033
}
1056-
}
1034+
},
10571035
};
1036+
10581037
let result = manifestation
10591038
.update_v1(
10601039
&manifest,

0 commit comments

Comments
 (0)