diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-03-24 07:20:43 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-03-24 07:20:43 +0000 |
commit | cf0972efd19976a9aa8e79fb7863d0440515bbd0 (patch) | |
tree | 452ff55e993a815da19fb6d5557adb4c36dd85ab | |
parent | 420cc245bbcb29bfb95d5784e64f6a7c85315225 (diff) | |
parent | c970ac8b443b7331610a36720f9b901146d9eed2 (diff) | |
download | obnam2-cf0972efd19976a9aa8e79fb7863d0440515bbd0.tar.gz |
Merge branch 'no-anyhow-in-lib' into 'main'
refactor(src/server.rs): drop use of anyhow::Result
See merge request larswirzenius/obnam!125
-rw-r--r-- | src/server.rs | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/server.rs b/src/server.rs index a464c6e..abf3f1e 100644 --- a/src/server.rs +++ b/src/server.rs @@ -28,17 +28,26 @@ 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(transparent)] + SerdeYamlError(#[from] serde_yaml::Error), } impl ServerConfig { - pub fn read_config(filename: &Path) -> anyhow::Result<Self> { - let config = std::fs::read_to_string(filename)?; + 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)), + }; let config: Self = serde_yaml::from_str(&config)?; config.check()?; Ok(config) } - pub fn check(&self) -> anyhow::Result<()> { + pub fn check(&self) -> Result<(), ServerConfigError> { if !self.chunks.exists() { return Err(ServerConfigError::ChunksDirNotFound(self.chunks.clone()).into()); } |