From 1c0dbb7bbae7ed2d33be6dd63a4cd4f7da00f10f Mon Sep 17 00:00:00 2001 From: nyyu Date: Mon, 15 Mar 2021 07:46:48 +0100 Subject: [PATCH] Remove unwrap --- src/main.rs | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/main.rs b/src/main.rs index b95df97..e819c64 100644 --- a/src/main.rs +++ b/src/main.rs @@ -45,12 +45,11 @@ const USER_AGENT_VALUE: &str = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:87.0) Gecko/20100101 Firefox/87.0"; const LOL_CHAMPS_DIR: &str = ".\\champs"; -fn main() { +fn main() -> Result<(), Box> { SimpleLogger::new() .with_level(LevelFilter::Info) .with_module_level("ureq", LevelFilter::Error) - .init() - .unwrap(); + .init()?; info!("CGG Item Sets"); @@ -58,7 +57,7 @@ fn main() { Ok(x) => x, Err(_e) => PathBuf::from(LOL_CHAMPS_DIR), }; - info!("LoL Champs Folder: {}", lol_champs_dir.to_str().unwrap()); + info!("LoL Champs Folder: {}", lol_champs_dir.to_str().unwrap_or(LOL_CHAMPS_DIR)); let client = ureq::AgentBuilder::new() .timeout(Duration::from_secs(10)) @@ -67,10 +66,8 @@ fn main() { let realm: Realm = client .get("https://ddragon.leagueoflegends.com/realms/euw.json") .set(USER_AGENT_KEY, USER_AGENT_VALUE) - .call() - .unwrap() - .into_json() - .unwrap(); + .call()? + .into_json()?; info!("LoL version: {}", realm.v); let champion: Champion = client @@ -79,10 +76,8 @@ fn main() { realm.v )) .set(USER_AGENT_KEY, USER_AGENT_VALUE) - .call() - .unwrap() - .into_json() - .unwrap(); + .call()? + .into_json()?; info!("LoL numbers of champs: {}", champion.data.len()); let data_sources: [Box; 3] = [ @@ -129,6 +124,7 @@ fn main() { } } } + Ok(()) } fn get_champ_from_key(champs: &Champion, key: &str) -> String {