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/modification.rs | 54 +++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 18 deletions(-) (limited to 'src/commands/modification.rs') diff --git a/src/commands/modification.rs b/src/commands/modification.rs index 6e6213f..aa1174a 100644 --- a/src/commands/modification.rs +++ b/src/commands/modification.rs @@ -44,7 +44,6 @@ pub struct ProjectInfo { } /// # Errors -/// # Panics pub async fn mod_add( config: &Cfg, mods: Vec, @@ -56,11 +55,14 @@ pub async fn mod_add( let mut mod_ids: Vec<(String, bool)> = Vec::new(); let mut ver_ids: Vec<(String, bool)> = Vec::new(); - let add_p = mp.add(ProgressBar::new(mods.len().try_into().map_err(|_| MLErr::new(EType::Other, "MODSLENTRY"))?)); + let add_p = mp.add(ProgressBar::new( + mods.len() + .try_into() + .map_err(|_| MLErr::new(EType::Other, "MODSLENTRY"))?, + )); add_p.set_style( - ProgressStyle::with_template(STYLE_BAR_POS).map_err(|_| { - MLErr::new(EType::LibIndicatif, "template error") - })? + ProgressStyle::with_template(STYLE_BAR_POS) + .map_err(|_| MLErr::new(EType::LibIndicatif, "template error"))? .progress_chars(PROGRESS_CHARS), ); add_p.set_message("Sort ids"); @@ -98,11 +100,16 @@ pub async fn mod_add( //Adding each mod to the lists and downloadstack let project_p = mp.insert_before( &add_p, - ProgressBar::new(projectinfo.len().try_into().unwrap()), + ProgressBar::new( + projectinfo + .len() + .try_into() + .map_err(|_| MLErr::new(EType::Other, "infolen"))?, + ), ); project_p.set_style( ProgressStyle::with_template(STYLE_BAR_POS) - .unwrap() + .map_err(|_| MLErr::new(EType::LibIndicatif, "template error"))? .progress_chars(PROGRESS_CHARS), ); @@ -112,7 +119,11 @@ pub async fn mod_add( let current_version_id = if project.current_version.is_none() { String::from("NONE") } else { - project.current_version.clone().unwrap().id + project + .current_version + .clone() + .ok_or(MLErr::new(EType::Other, "cur_ver"))? + .id }; match userlist_insert( @@ -158,7 +169,11 @@ pub async fn mod_add( }?; if project.current_version.is_some() { - downloadstack.push(project.current_version.unwrap()); + downloadstack.push( + project + .current_version + .ok_or(MLErr::new(EType::Other, "cur_ver"))?, + ); }; project_p.inc(1); @@ -202,8 +217,8 @@ async fn get_mod_infos( //Get required information from mod_ids let m_projects = match ids.len() { - 1 => vec![project(&config.apis.modrinth, &ids[0]).await], - 2.. => projects(&config.apis.modrinth, ids).await, + 1 => vec![project(&config.apis.modrinth, &ids[0]).await?], + 2.. => projects(&config.apis.modrinth, ids).await?, _ => panic!("PANIC"), }; for project in m_projects { @@ -212,7 +227,7 @@ async fn get_mod_infos( String::from(&project.id), list.clone(), ) - .await; + .await?; let mut available_versions_vec: Vec = Vec::new(); let current_version: Option; @@ -228,7 +243,9 @@ async fn get_mod_infos( current_version, applicable_versions: available_versions_vec, download_link: file, - set_version: *setmap.get(&project.id).unwrap(), + set_version: *setmap + .get(&project.id) + .ok_or(MLErr::new(EType::Other, "not in setmap"))?, }); } else { let current_id = @@ -285,12 +302,12 @@ async fn get_ver_info( let mut projectinfo: Vec = Vec::new(); //Get required information from ver_ids - let mut v_versions = get_raw_versions(&config.apis.modrinth, ids).await; + let mut v_versions = get_raw_versions(&config.apis.modrinth, ids).await?; let mut v_mod_ids: Vec = Vec::new(); for ver in v_versions.clone() { v_mod_ids.push(ver.project_id); } - let mut v_projects = projects(&config.apis.modrinth, v_mod_ids).await; + let mut v_projects = projects(&config.apis.modrinth, v_mod_ids).await?; v_versions.sort_by(|a, b| a.project_id.cmp(&b.project_id)); v_projects.sort_by(|a, b| a.id.cmp(&b.id)); @@ -328,9 +345,10 @@ async fn get_ver_info( /// # Errors pub fn mod_remove(config: &Cfg, id: &str, list: &List) -> MLE<()> { let progress = ProgressBar::new_spinner(); - progress.set_style(ProgressStyle::with_template(STYLE_OPERATION).map_err(|_| { - MLErr::new(EType::LibIndicatif, "template error") - })?); + progress.set_style( + ProgressStyle::with_template(STYLE_OPERATION) + .map_err(|_| MLErr::new(EType::LibIndicatif, "template error"))?, + ); let mod_id = mods_get_id(&config.data, id)?; -- cgit v1.2.3