diff --git a/src/apps.rs b/src/apps.rs index 2a3e60b..c707c1b 100644 --- a/src/apps.rs +++ b/src/apps.rs @@ -1,3 +1,4 @@ +use std::boxed::Box; use std::fs::File; use std::io::Read; use std::path::PathBuf; @@ -12,11 +13,29 @@ pub struct Apps { } impl Apps { - pub fn load>(p: T) -> Result { - let mut file = File::open(p.into())?; - let mut buf = String::new(); - file.read_to_string(&mut buf)?; - Ok(toml::from_str(&buf)?) + pub fn load(p: PathBuf) -> Result { + match File::open(p.into()) { + Ok(file) => { + let mut buf = String::new(); + + if let Err(e) = file.read_to_string(&mut buf) { + error!("unable to read apps file: {}: {:?}", p.display(), e); + return Err(Box::new(e)); + }; + + match toml::from_str(&buf) { + Ok(t) => Ok(t), + Err(e) => { + error!("Invalid toml in apps file: {}: {:?}", p.display(), e); + Err(Box::new(e)) + } + } + } + Err(e) => { + error!("Unable to open apps file: {}: {:?}", p.display(), e); + Err(Box::new(e)) + } + } } pub fn apps(&self) -> Vec {