From 968eba80e6d729889b1ac3179efd96b685e0efa5 Mon Sep 17 00:00:00 2001 From: Tarasov Aleksandr <55220741+arabianq@users.noreply.github.com> Date: Sun, 8 Mar 2026 00:28:09 +0300 Subject: [PATCH] Fix: Prevent panic on invalid configuration files (#26) When the user's daemon.json or gui.json configuration files become corrupted or invalid (e.g. invalid JSON), the application panics as the load_from_file function previously bubbled up the error causing a panic. This fix modifies load_from_file for both DaemonConfig and GuiConfig to catch JSON parsing errors using a match statement and return a Default configuration instead. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> --- src/types/config.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/types/config.rs b/src/types/config.rs index 84b86f2..f28e1da 100644 --- a/src/types/config.rs +++ b/src/types/config.rs @@ -27,7 +27,10 @@ impl DaemonConfig { pub fn load_from_file() -> Result> { let config_path = get_config_path()?.join("daemon.json"); let bytes = fs::read(config_path)?; - Ok(serde_json::from_slice::(&bytes)?) + match serde_json::from_slice::(&bytes) { + Ok(config) => Ok(config), + Err(_) => Ok(DaemonConfig::default()), + } } } @@ -84,6 +87,9 @@ impl GuiConfig { pub fn load_from_file() -> Result> { let config_path = get_config_path()?.join("gui.json"); let bytes = fs::read(config_path)?; - Ok(serde_json::from_slice::(&bytes)?) + match serde_json::from_slice::(&bytes) { + Ok(config) => Ok(config), + Err(_) => Ok(GuiConfig::default()), + } } }