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/spec.rs | |
parent | 6497e12ae4df4c7cb98992f5cf1948b3eebc486d (diff) | |
download | vmadm-23138e5bdb8ca751834009d99d85b37e5e4ae5ae.tar.gz |
feat: give more useful and specific error messages
Diffstat (limited to 'src/spec.rs')
-rw-r--r-- | src/spec.rs | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/spec.rs b/src/spec.rs index b9828e9..a1d1c2f 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -216,14 +216,14 @@ pub enum SpecificationError { #[error("No SSH authorized keys specified for {0} and no default configured")] NoAuthorizedKeys(String), + /// Error reading specification file. + #[error("Couldn't read specification file {0}")] + Read(PathBuf, #[source] std::io::Error), + /// Error reading SSH public key. #[error("Failed to read SSH public key file {0}")] SshKeyRead(PathBuf, #[source] std::io::Error), - /// I/O error. - #[error(transparent)] - IoError(#[from] std::io::Error), - /// Error parsing string as UTF8. #[error(transparent)] FromUtf8Error(#[from] std::string::FromUtf8Error), @@ -247,7 +247,8 @@ impl Specification { filename: &Path, ) -> Result<Vec<Specification>, SpecificationError> { debug!("reading specification from {}", filename.display()); - let spec = fs::read(filename)?; + let spec = fs::read(filename) + .map_err(|err| SpecificationError::Read(filename.to_path_buf(), err))?; let input: HashMap<String, OneVmInputSpecification> = serde_yaml::from_slice(&spec)?; debug!("specification as read from file: {:#?}", input); |