Panic if config file is bad

This commit is contained in:
Luke D Jones
2020-10-22 08:28:12 +13:00
parent 6ce32c1cab
commit 588e3c0102

View File

@@ -30,18 +30,18 @@ impl Config {
.write(true) .write(true)
.create(true) .create(true)
.open(&CONFIG_PATH) .open(&CONFIG_PATH)
.expect(&format!("The file {} or directory /etc/asusd/ is missing", CONFIG_PATH)); // okay to cause panic here .expect(&format!(
"The file {} or directory /etc/asusd/ is missing",
CONFIG_PATH
)); // okay to cause panic here
let mut buf = String::new(); let mut buf = String::new();
if let Ok(l) = file.read_to_string(&mut buf) { if let Ok(l) = file.read_to_string(&mut buf) {
if l == 0 { if l == 0 {
self = Config::create_default(&mut file, &supported_led_modes); self = Config::create_default(&mut file, &supported_led_modes);
} else { } else {
self = serde_json::from_str(&buf).unwrap_or_else(|_| { self = serde_json::from_str(&buf).unwrap_or_else(|_| {
warn!( warn!("Could not deserialise {}", CONFIG_PATH);
"Could not deserialise {}. Overwriting with default", panic!("Please remove {} then restart asusd", CONFIG_PATH);
CONFIG_PATH
);
Config::create_default(&mut file, &supported_led_modes)
}); });
} }
} }