mirror of
https://github.com/arabianq/pipewire-soundpad.git
synced 2026-04-28 14:31:23 +00:00
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>
This commit is contained in:
committed by
GitHub
parent
aa77a8d212
commit
968eba80e6
+8
-2
@@ -27,7 +27,10 @@ impl DaemonConfig {
|
||||
pub fn load_from_file() -> Result<DaemonConfig, Box<dyn Error>> {
|
||||
let config_path = get_config_path()?.join("daemon.json");
|
||||
let bytes = fs::read(config_path)?;
|
||||
Ok(serde_json::from_slice::<DaemonConfig>(&bytes)?)
|
||||
match serde_json::from_slice::<DaemonConfig>(&bytes) {
|
||||
Ok(config) => Ok(config),
|
||||
Err(_) => Ok(DaemonConfig::default()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,6 +87,9 @@ impl GuiConfig {
|
||||
pub fn load_from_file() -> Result<GuiConfig, Box<dyn Error>> {
|
||||
let config_path = get_config_path()?.join("gui.json");
|
||||
let bytes = fs::read(config_path)?;
|
||||
Ok(serde_json::from_slice::<GuiConfig>(&bytes)?)
|
||||
match serde_json::from_slice::<GuiConfig>(&bytes) {
|
||||
Ok(config) => Ok(config),
|
||||
Err(_) => Ok(GuiConfig::default()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user