From 77f37bc8b82d2988e8bdd27b4b87a425eaa72244 Mon Sep 17 00:00:00 2001 From: Songtronix Date: Thu, 4 Jul 2019 19:37:56 +0200 Subject: [PATCH] maybe improved setting file handling --- server/src/settings.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/server/src/settings.rs b/server/src/settings.rs index 3ba8482cc3..ef168b3266 100644 --- a/server/src/settings.rs +++ b/server/src/settings.rs @@ -29,14 +29,22 @@ impl ServerSettings { pub fn load() -> Self { let path = ServerSettings::get_settings_path(); - // If file doesn't exist, use the default settings. if let Ok(file) = fs::File::open(path) { - // TODO: Replace expect with returning default? - ron::de::from_reader(file).expect("Error parsing settings") + match ron::de::from_reader(file) { + Ok(x) => x, + Err(e) => { + log::warn!("Failed to parse setting file! Fallback to default. {}", e); + Self::default() + } + } } else { - // TODO: temporary - Self::default().save_to_file().unwrap(); - Self::default() + let default_settings = Self::default(); + + match default_settings.save_to_file() { + Err(e) => log::error!("Failed to create default setting file! {}", e), + _ => {} + } + default_settings } }