diff --git a/CHANGELOG.md b/CHANGELOG.md index a4c3cc21..0eb390bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ Thanks to @nate-sys and @jubalh for contributing to this release. - `/join` command errors now print usage help once instead of twice. - Fix showing timestamp of the next message or activity after a `/clear`. (#417) +- Fix a crash when the config file is deleted before a `/reload`. # 2023/07/16: 0.11.0 diff --git a/crates/libtiny_tui/src/config.rs b/crates/libtiny_tui/src/config.rs index 560893fc..336f6b15 100644 --- a/crates/libtiny_tui/src/config.rs +++ b/crates/libtiny_tui/src/config.rs @@ -5,8 +5,6 @@ use libtiny_common::{ChanName, ChanNameRef}; use serde::de::{self, Deserializer, MapAccess, Visitor}; use serde::Deserialize; use std::collections::HashMap; -use std::fs::File; -use std::io::Read; use std::path::Path; use std::str::FromStr; @@ -510,12 +508,14 @@ impl<'de> Deserialize<'de> for Style { } pub(crate) fn parse_config(config_path: &Path) -> Result { - let contents = { - let mut str = String::new(); - let mut file = File::open(config_path).unwrap(); - file.read_to_string(&mut str).unwrap(); - str - }; - + // tiny creates a config file with the defaults when it can't find one, but the config file can + // be deleted before a `/reload`. + let contents = std::fs::read_to_string(config_path).map_err(|err| { + de::Error::custom(format!( + "Can't read config file '{}': {}", + config_path.to_string_lossy(), + err + )) + })?; serde_yaml::from_str(&contents) } diff --git a/crates/libtiny_tui/src/tui.rs b/crates/libtiny_tui/src/tui.rs index b4c4abf1..ba950d30 100644 --- a/crates/libtiny_tui/src/tui.rs +++ b/crates/libtiny_tui/src/tui.rs @@ -344,7 +344,7 @@ impl TUI { match parse_config(config_path) { Err(err) => { self.add_client_err_msg( - &format!("Can't parse TUI config: {:?}", err), + &format!("Can't parse TUI config: {}", err), &MsgTarget::CurrentTab, ); None