From a29ab33d662f05bad91ece7dc2eb052ac451a604 Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy Date: Tue, 15 Sep 2026 13:56:37 +0200 Subject: [PATCH] fix(cosmic-config): handle io::ErrorKind::NotFound as Error::NotFound Fixes excess logs and inability to fallback to system default of config --- cosmic-config/src/lib.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/cosmic-config/src/lib.rs b/cosmic-config/src/lib.rs index e51b4f6a..71f3d2d2 100644 --- a/cosmic-config/src/lib.rs +++ b/cosmic-config/src/lib.rs @@ -4,7 +4,7 @@ use notify::event::{EventKind, ModifyKind, RenameMode}; use notify::{RecommendedWatcher, Watcher}; use serde::Serialize; use serde::de::DeserializeOwned; -use std::io::Write; +use std::io::{self, Write}; use std::path::{Path, PathBuf}; use std::sync::Mutex; use std::{env, fmt, fs}; @@ -417,10 +417,11 @@ impl ConfigGet for Config { match self.key_path(key) { Ok(key_path) if key_path.is_file() => { // Load user override - let data = fs::read_to_string(key_path) - .map_err(|err| Error::GetKey(key.to_string(), err))?; - - Ok(ron::from_str(&data)?) + match fs::read_to_string(key_path) { + Ok(data) => Ok(ron::from_str(&data)?), + Err(why) if why.kind() == io::ErrorKind::NotFound => Err(Error::NotFound), + Err(why) => Err(Error::GetKey(key.to_string(), why)), + } } _ => { @@ -436,9 +437,11 @@ impl ConfigGet for Config { fn get_system_default(&self, key: &str) -> Result { // Load system default let default_path = self.default_path(key)?; - let data = - fs::read_to_string(default_path).map_err(|err| Error::GetKey(key.to_string(), err))?; - Ok(ron::from_str(&data)?) + match fs::read_to_string(default_path) { + Ok(data) => Ok(ron::from_str(&data)?), + Err(why) if why.kind() == io::ErrorKind::NotFound => Err(Error::NotFound), + Err(why) => Err(Error::GetKey(key.to_string(), why)), + } } }