From 1227a143147295bac8a77ca50c545221a5ce6185 Mon Sep 17 00:00:00 2001 From: Dorian Rudolph Date: Fri, 8 Jul 2022 15:53:01 +0200 Subject: [PATCH] handle parse error of history file --- src/history.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/history.rs b/src/history.rs index d3537df..7b265a1 100644 --- a/src/history.rs +++ b/src/history.rs @@ -20,8 +20,11 @@ impl PartialEq for HistoryData { pub fn load_history() -> HashMap { 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() }