diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-03-25 09:57:21 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-03-25 11:34:01 +0200 |
commit | 23138e5bdb8ca751834009d99d85b37e5e4ae5ae (patch) | |
tree | 27e9b77e04a877a3efdb7b9795f5977060b3488a /src/config.rs | |
parent | 6497e12ae4df4c7cb98992f5cf1948b3eebc486d (diff) | |
download | vmadm-23138e5bdb8ca751834009d99d85b37e5e4ae5ae.tar.gz |
feat: give more useful and specific error messages
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/config.rs b/src/config.rs index 88c186b..1866971 100644 --- a/src/config.rs +++ b/src/config.rs @@ -41,9 +41,9 @@ pub struct Configuration { /// Errors from this module. #[derive(Debug, thiserror::Error)] pub enum ConfigurationError { - /// I/O error. - #[error(transparent)] - IoError(#[from] std::io::Error), + /// Error reading configuration file. + #[error("couldn't read configuration file {0}")] + ReadError(PathBuf, #[source] std::io::Error), /// YAML parsing error. #[error(transparent)] @@ -55,7 +55,8 @@ impl Configuration { pub fn from_file(filename: &Path) -> Result<Self, ConfigurationError> { if filename.exists() { debug!("reading configuration file {}", filename.display()); - let config = fs::read(filename)?; + let config = fs::read(filename) + .map_err(|err| ConfigurationError::ReadError(filename.to_path_buf(), err))?; let config: Configuration = serde_yaml::from_slice(&config)?; debug!("config: {:#?}", config); Ok(config) |