From 6f2ad6990a40a1eba5c1919c78f4172ad07bfc9c Mon Sep 17 00:00:00 2001 From: Sakuhl <2012collector@gmail.com> Date: Mon, 15 Jan 2018 15:20:42 +0100 Subject: [PATCH] Improve error handling --- src/main.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index d18f612..f762550 100644 --- a/src/main.rs +++ b/src/main.rs @@ -42,13 +42,21 @@ fn main() { guild_list.into_iter().for_each(|name| { thread::sleep_ms(2500); - println!("Getting {:?}", name); - let guild = Guild { prefix: wynncraft::guild(&name).unwrap().unwrap().prefix, name }; - diesel::insert_into(guilds::table) - .values(&guild) - .on_conflict(guilds::prefix) - .do_nothing() - .execute(&conn).unwrap(); + println!("Getting {:?} -> ", name); + if let Ok(Some(prefix)) = wynncraft::guild(&name).map(|x| x.map(|x| x.prefix)) { + let guild = Guild { prefix, name }; + if let Ok(_) = diesel::insert_into(guilds::table) + .values(&guild) + .on_conflict(guilds::prefix) + .do_nothing() + .execute(&conn) { + + } else { + println!("Fail!"); + } + } else { + println!("Fail!"); + } }); println!("Guilds updated!");