diff --git a/src/app/config.rs b/src/app/config.rs index 270f45ae..f6d49514 100644 --- a/src/app/config.rs +++ b/src/app/config.rs @@ -83,9 +83,14 @@ impl Config { fn load_file() -> Option { if let Ok(config_path) = env::var("PATCH_HUB_CONFIG_PATH") { if Path::new(&config_path).is_file() { - let file_contents = fs::read_to_string(&config_path).unwrap_or(String::new()); - if let Ok(config) = serde_json::from_str(&file_contents) { - return Some(config); + match fs::read_to_string(&config_path) { + Ok(file_contents) => match serde_json::from_str(&file_contents) { + Ok(config) => return Some(config), + Err(e) => eprintln!("Failed to parse config file {}: {}", config_path, e), + }, + Err(e) => { + eprintln!("Failed to read config file {}: {}", config_path, e) + } } } } @@ -95,9 +100,14 @@ impl Config { env::var("HOME").unwrap() ); if Path::new(&config_path).is_file() { - let file_contents = fs::read_to_string(&config_path).unwrap_or(String::new()); - if let Ok(config) = serde_json::from_str(&file_contents) { - return Some(config); + match fs::read_to_string(&config_path) { + Ok(file_contents) => match serde_json::from_str(&file_contents) { + Ok(config) => return Some(config), + Err(e) => eprintln!("Failed to parse config file {}: {}", config_path, e), + }, + Err(e) => { + eprintln!("Failed to read config file {}: {}", config_path, e) + } } } @@ -128,9 +138,11 @@ impl Config { pub fn build() -> Self { let mut config = Self::load_file().unwrap_or_else(|| { + eprintln!("No valid config file found, using default configuration"); let config = Self::default(); - // TODO: Better handle this error - let _ = config.save_patch_hub_config(); + config.save_patch_hub_config().unwrap_or_else(|e| { + eprintln!("Failed to save default config: {}", e); + }); config });