From 29635b9e3833296b2c908914104ba7165d22d3d5 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Wed, 4 Sep 2024 12:03:13 +0200 Subject: remove `# Panics` and fix clippy --- src/commands/download.rs | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'src/commands/download.rs') diff --git a/src/commands/download.rs b/src/commands/download.rs index 7321832..7af1066 100644 --- a/src/commands/download.rs +++ b/src/commands/download.rs @@ -15,7 +15,6 @@ use crate::{ use crate::{PROGRESS_CHARS, STYLE_BAR_POS}; /// # Errors -/// # Panics pub async fn download( config: &Cfg, liststack: Vec, @@ -23,29 +22,31 @@ pub async fn download( delete_old: bool, ) -> MLE<()> { let mp = MultiProgress::new(); - let download_p = - mp.add(ProgressBar::new(liststack.len().try_into().unwrap())); + let download_p = mp.add(ProgressBar::new( + liststack + .len() + .try_into() + .map_err(|_| MLErr::new(EType::Other, "ListStackLen"))?, + )); download_p.set_style( ProgressStyle::with_template(STYLE_BAR_POS) - .unwrap() + .map_err(|_| MLErr::new(EType::LibIndicatif, "template error"))? .progress_chars(PROGRESS_CHARS), ); for current_list in liststack { download_p.set_message(format!("Download in {}", current_list.id)); - let downloaded_versions = - get_downloaded_versions(¤t_list)?; + let downloaded_versions = get_downloaded_versions(¤t_list)?; let current_version_ids = match userlist_get_all_current_versions_with_mods( config, ¤t_list.id, ) { Ok(i) => Ok(i), - Err(e) => Err(MLErr::new( - EType::DBError, - e.to_string().as_str(), - )), + Err(e) => { + Err(MLErr::new(EType::DBError, e.to_string().as_str())) + } }?; let mut to_download: Vec = vec![]; @@ -62,8 +63,7 @@ pub async fn download( to_download.push(current_version); } else { let downloaded_version = current_download - .ok_or("SOMETHING_HAS_REALLY_GONE_WRONG") - .unwrap(); + .ok_or(MLErr::new(EType::Other, "IDK, WTF"))?; if ¤t_version != downloaded_version { to_disable.push(( mod_id.clone(), @@ -87,7 +87,7 @@ pub async fn download( download_versions( current_list.clone(), config.clone(), - get_raw_versions(&config.apis.modrinth, to_download).await, + get_raw_versions(&config.apis.modrinth, to_download).await?, &mp, &download_p, ) @@ -95,13 +95,18 @@ pub async fn download( } if !to_disable.is_empty() { - let d_p = mp.insert_before( - &download_p, - ProgressBar::new(to_disable.len().try_into().unwrap()), - ); + let d_p = + mp.insert_before( + &download_p, + ProgressBar::new(to_disable.len().try_into().map_err( + |_| MLErr::new(EType::Other, "ListStackLen"), + )?), + ); d_p.set_style( ProgressStyle::with_template(STYLE_BAR_POS) - .unwrap() + .map_err(|_| { + MLErr::new(EType::LibIndicatif, "template error") + })? .progress_chars(PROGRESS_CHARS), ); for ver in to_disable { @@ -112,12 +117,7 @@ pub async fn download( } else { d_p.set_message(format!("Disable version {}", ver.1)); d_p.inc(1); - disable_version( - config, - ¤t_list, - ver.1, - ver.0, - )?; + disable_version(config, ¤t_list, ver.1, ver.0)?; }; } -- cgit v1.2.3