operations: Replace unwrap_or_else with if let Err

i18n
Fries 2 years ago committed by fries1234
parent 2ae9ea34dd
commit 6b90744230

@ -49,18 +49,19 @@ pub async fn clean(options: Options) {
tracing::debug!("Removing orphans: {:?}", orphaned_packages_vec); tracing::debug!("Removing orphans: {:?}", orphaned_packages_vec);
// Remove orphaned packages // Remove orphaned packages
PacmanUninstallBuilder::default() let result = PacmanUninstallBuilder::default()
.no_save(true) .no_save(true)
.recursive(true) .recursive(true)
.no_confirm(noconfirm) .no_confirm(noconfirm)
.packages(orphaned_packages_vec) .packages(orphaned_packages_vec)
.uninstall() .uninstall()
.await .await;
.unwrap_or_else(|_| {
crash!(AppExitCode::PacmanError, "Failed to remove orphans",);
});
tracing::info!("Successfully removed orphans"); if let Err(_) = result {
crash!(AppExitCode::PacmanError, "Failed to remove orphans");
} else {
tracing::info!("Successfully removed orphans");
}
} }
// Prompt the user whether to clear the Amethyst cache // Prompt the user whether to clear the Amethyst cache
@ -89,20 +90,21 @@ pub async fn clean(options: Options) {
// Clear pacman's cache // Clear pacman's cache
// keeps 0 versions of the package in the cache by default // keeps 0 versions of the package in the cache by default
// keeps installed packages in the cache by default // keeps installed packages in the cache by default
PaccacheBuilder::default() let result = PaccacheBuilder::default()
.keep(conf.base.paccache_keep) .keep(conf.base.paccache_keep)
.keep_ins(conf.base.paccache_keep_ins) .keep_ins(conf.base.paccache_keep_ins)
.quiet(quiet) .quiet(quiet)
.remove() .remove()
.await .await;
.unwrap_or_else(|e| {
crash!(
AppExitCode::PacmanError,
"Failed to clear package cache, {}",
e
)
});
tracing::info!("Successfully cleared package cache"); if let Err(e) = result {
crash!(
AppExitCode::PacmanError,
"Failed to clear package cache, {}",
e
)
} else {
tracing::info!("Successfully cleared package cache");
}
} }
} }

@ -28,20 +28,22 @@ async fn upgrade_repo(options: Options) {
tracing::debug!("Upgrading repo packages"); tracing::debug!("Upgrading repo packages");
PacmanUpgradeBuilder::default() let result = PacmanUpgradeBuilder::default()
.no_confirm(noconfirm) .no_confirm(noconfirm)
.upgrade() .upgrade()
.await .await;
.unwrap_or_else(|_| {
let continue_upgrading = prompt!(default no, if let Err(_) = result {
"Failed to upgrade repo packages, continue to upgrading AUR packages?", let continue_upgrading = prompt!(default no,
); "Failed to upgrade repo packages, continue to upgrading AUR packages?",
if !continue_upgrading { );
tracing::info!("Exiting"); if !continue_upgrading {
std::process::exit(AppExitCode::PacmanError as i32); tracing::info!("Exiting");
} std::process::exit(AppExitCode::PacmanError as i32);
}); }
tracing::info!("Successfully upgraded repo packages"); } else {
tracing::info!("Successfully upgraded repo packages");
}
} }
#[tracing::instrument(level = "trace")] #[tracing::instrument(level = "trace")]

Loading…
Cancel
Save