fix(cosmic-config): handle io::ErrorKind::NotFound as Error::NotFound

Fixes excess logs and inability to fallback to system default of config
This commit is contained in:
Michael Aaron Murphy 2026-09-15 13:56:37 +02:00
parent 23f5d63fed
commit a29ab33d66
No known key found for this signature in database
GPG key ID: B2732D4240C9212C

View file

@ -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<T: DeserializeOwned>(&self, key: &str) -> Result<T, Error> {
// 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)),
}
}
}