summaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-04-24 08:18:56 +0300
committerLars Wirzenius <liw@liw.fi>2021-04-29 10:51:31 +0300
commit80ae98bf87c57aa361a13c3dd925455fb67e3f03 (patch)
treeaca3860996a6ebd622802d6a41493008189203ab /src/config.rs
parentbf645f3645fd2ee57495eafd1ccfb4afbe917bec (diff)
downloadobnam2-80ae98bf87c57aa361a13c3dd925455fb67e3f03.tar.gz
feat: improve error messages
All unclear error messages should now be clearer. For example, all the ones related to a file mention the file name and the attempted operation that failed.
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/config.rs b/src/config.rs
index b30cfa3..33e08a2 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -77,11 +77,11 @@ pub enum ClientConfigError {
#[error("No passwords are set: you may need to run 'obnam init': {0}")]
PasswordsMissing(PasswordError),
- #[error(transparent)]
- IoError(#[from] std::io::Error),
+ #[error("failed to read configuration file {0}: {1}")]
+ Read(PathBuf, std::io::Error),
- #[error(transparent)]
- SerdeYamlError(#[from] serde_yaml::Error),
+ #[error("failed to parse configuration file {0} as YAML: {1}")]
+ YamlParse(PathBuf, serde_yaml::Error),
}
pub type ClientConfigResult<T> = Result<T, ClientConfigError>;
@@ -89,8 +89,10 @@ pub type ClientConfigResult<T> = Result<T, ClientConfigError>;
impl ClientConfigWithoutPasswords {
pub fn read_config(filename: &Path) -> ClientConfigResult<Self> {
trace!("read_config: filename={:?}", filename);
- let config = std::fs::read_to_string(filename)?;
- let tentative: TentativeClientConfig = serde_yaml::from_str(&config)?;
+ let config = std::fs::read_to_string(filename)
+ .map_err(|err| ClientConfigError::Read(filename.to_path_buf(), err))?;
+ let tentative: TentativeClientConfig = serde_yaml::from_str(&config)
+ .map_err(|err| ClientConfigError::YamlParse(filename.to_path_buf(), err))?;
let roots = tentative
.roots
.iter()