Skip to content

Commit

Permalink
Fix a crash when the config file is deleted before a /reload
Browse files Browse the repository at this point in the history
  • Loading branch information
osa1 committed Dec 31, 2023
1 parent efa1d22 commit 3ea5678
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 9 additions & 9 deletions crates/libtiny_tui/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -510,12 +508,14 @@ impl<'de> Deserialize<'de> for Style {
}

pub(crate) fn parse_config(config_path: &Path) -> Result<Config, serde_yaml::Error> {
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)
}
2 changes: 1 addition & 1 deletion crates/libtiny_tui/src/tui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3ea5678

Please sign in to comment.