From 4ad3c335e52f8ced3c1e01225b8fee074587de20 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Fri, 3 Nov 2023 09:40:06 -0400 Subject: [PATCH] Better parsing --- src/main.rs | 47 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/src/main.rs b/src/main.rs index f20a434..8bc0cab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -116,15 +116,22 @@ async fn parse_log(log_data: Vec) -> Box { let (key, value) = line.split_once(":").unwrap(); match key.trim() { "Whisky Version" => { - log_header.whisky_version.0 = - Version::parse(value.trim()).expect("Failed to parse version"); + match Version::parse(value.trim()) { + Err(_) => println!("Whisky Version not found!"), + Ok(i) => log_header.whisky_version.0 = i + } } "Date" => { - log_header.date = date(value.trim()).unwrap(); + match date(value.trim()) { + Err(_) => println!("Date not found!"), + Ok(i) => log_header.date = i + } } "macOS Version" => { - log_header.macos_version.0 = - Version::parse(value.trim()).expect("Failed to parse version"); + match Version::parse(value.trim()) { + Err(_) => println!("macOS Version not found!"), + Ok(i) => log_header.macos_version.0 = i + } } "Bottle Name" => { log_header.bottle_name = value.trim().to_string(); @@ -133,27 +140,39 @@ async fn parse_log(log_data: Vec) -> Box { log_header.bottle_url = value.trim().to_string(); } "Wine Version" => { - log_header.wine_version.0 = - Version::parse(value.trim()).expect("Failed to parse version"); + match Version::parse(value.trim()) { + Err(_) => println!("Wine Version not found!"), + Ok(i) => log_header.wine_version.0 = i + } } "Windows Version" => { - log_header.windows_version = - header::WinVersion::from_str(value.trim()).unwrap(); + match header::WinVersion::from_str(value.trim()) { + Err(_) => println!("Windows Version not found!"), + Ok(i) => log_header.windows_version = i + } } "Enhanced Sync" => { - log_header.enhanced_sync = - header::EnhancedSync::from_str(value.trim()).unwrap(); + match header::EnhancedSync::from_str(value.trim()) { + Err(_) => println!("Enhanced Sync not found!"), + Ok(i) => log_header.enhanced_sync = i + } } "Metal HUD" => { - log_header.metal_hud = value.trim().parse().unwrap(); + match value.trim().parse() { + Err(_) => println!("Metal HUD not found!"), + Ok(i) => log_header.metal_hud = i + } } "Metal Trace" => { - log_header.metal_trace = value.trim().parse().unwrap(); + match value.trim().parse() { + Err(_) => println!("Metal Trace not found!"), + Ok(i) => log_header.metal_trace = i + } } "Arguments" => { log_header.arguments = value.trim().to_string(); } - _ => println!("Don't care"), + _ => println!("Found unknown key '{key}'"), } } }