diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-04-24 08:18:56 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-04-29 10:51:31 +0300 |
commit | 80ae98bf87c57aa361a13c3dd925455fb67e3f03 (patch) | |
tree | aca3860996a6ebd622802d6a41493008189203ab /src/server.rs | |
parent | bf645f3645fd2ee57495eafd1ccfb4afbe917bec (diff) | |
download | obnam2-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/server.rs')
-rw-r--r-- | src/server.rs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/server.rs b/src/server.rs index 6ea8ac4..3b0584f 100644 --- a/src/server.rs +++ b/src/server.rs @@ -29,20 +29,20 @@ pub enum ServerConfigError { #[error("server address can't be resolved")] BadServerAddress, - #[error("I/O error for {0}: {1}")] - IoError(PathBuf, #[source] 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 as YAML: {0}")] + YamlParse(serde_yaml::Error), } impl ServerConfig { pub fn read_config(filename: &Path) -> Result<Self, ServerConfigError> { let config = match std::fs::read_to_string(filename) { Ok(config) => config, - Err(err) => return Err(ServerConfigError::IoError(filename.to_path_buf(), err)), + Err(err) => return Err(ServerConfigError::Read(filename.to_path_buf(), err)), }; - let config: Self = serde_yaml::from_str(&config)?; + let config: Self = serde_yaml::from_str(&config).map_err(ServerConfigError::YamlParse)?; config.check()?; Ok(config) } |