From 9b44923e910be666bc287c03e8601486416f653b Mon Sep 17 00:00:00 2001 From: cat_or_not <41955154+catornot@users.noreply.github.com> Date: Sat, 29 Apr 2023 19:37:42 -0400 Subject: refactor: Use error in `ParsedThunderstoreModString::FromStr` instead of panic (#295) report error instead of panic --- src-tauri/src/mod_management/mod.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src-tauri/src/mod_management') diff --git a/src-tauri/src/mod_management/mod.rs b/src-tauri/src/mod_management/mod.rs index 728e72c0..25dea2bb 100644 --- a/src-tauri/src/mod_management/mod.rs +++ b/src-tauri/src/mod_management/mod.rs @@ -16,18 +16,18 @@ use app::GameInstall; struct ParsedThunderstoreModString { author_name: String, mod_name: String, - version: Option, + version: String, } impl std::str::FromStr for ParsedThunderstoreModString { - type Err = (); + type Err = &'static str; // todo use an better error management fn from_str(s: &str) -> Result { let mut parts = s.split('-'); - let author_name = parts.next().unwrap().to_string(); - let mod_name = parts.next().unwrap().to_string(); - let version = parts.next().map(|s| s.to_string()); + let author_name = parts.next().ok_or("None value on author_name")?.to_string(); + let mod_name = parts.next().ok_or("None value on mod_name")?.to_string(); + let version = parts.next().ok_or("None value on version")?.to_string(); Ok(ParsedThunderstoreModString { author_name, @@ -268,7 +268,7 @@ async fn get_ns_mod_download_url(thunderstore_mod_string: &str) -> Result