handle parse error of history file

This commit is contained in:
Dorian Rudolph 2022-07-08 15:53:01 +02:00
parent 3714e5e0be
commit 1227a14314

View File

@ -20,8 +20,11 @@ impl PartialEq for HistoryData {
pub fn load_history() -> HashMap<String, HistoryData> {
match get_history_file(false) {
Some(file) => {
let config_str = std::fs::read_to_string(file).expect("Cannot read history file");
toml::from_str(&config_str).expect("Cannot parse config: {}")
let history_str = std::fs::read_to_string(file).expect("Cannot read history file");
toml::from_str(&history_str).unwrap_or_else(|err| {
eprintln!("Cannot parse history file: {}", err);
HashMap::new()
})
},
_ => HashMap::new()
}