From aa77a8d212efb2e7f23749f6a9515605cd0097ee Mon Sep 17 00:00:00 2001 From: Tarasov Aleksandr <55220741+arabianq@users.noreply.github.com> Date: Sun, 8 Mar 2026 00:26:45 +0300 Subject: [PATCH] refactor: replace unsafe `unwrap` with `if let` in config saving (#24) Removed the unsafe `.unwrap()` call when attempting to get the parent directory of `config_path` in `DaemonConfig::save_to_file` and `GuiConfig::save_to_file`. Replaced it with an idiomatic `if let Some(config_dir)` check to improve code safety and maintainability. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> --- src/types/config.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/types/config.rs b/src/types/config.rs index 44f566a..84b86f2 100644 --- a/src/types/config.rs +++ b/src/types/config.rs @@ -12,10 +12,11 @@ pub struct DaemonConfig { impl DaemonConfig { pub fn save_to_file(&self) -> Result<(), Box> { let config_path = get_config_path()?.join("daemon.json"); - let config_dir = config_path.parent().unwrap(); - if !config_path.exists() { - fs::create_dir_all(config_dir)?; + if let Some(config_dir) = config_path.parent() { + if !config_path.exists() { + fs::create_dir_all(config_dir)?; + } } let config_json = serde_json::to_string_pretty(self)?; @@ -63,10 +64,11 @@ impl Default for GuiConfig { impl GuiConfig { pub fn save_to_file(&mut self) -> Result<(), Box> { let config_path = get_config_path()?.join("gui.json"); - let config_dir = config_path.parent().unwrap(); - if !config_path.exists() { - fs::create_dir_all(config_dir)?; + if let Some(config_dir) = config_path.parent() { + if !config_path.exists() { + fs::create_dir_all(config_dir)?; + } } // Do not save scale factor if user does not want to