summaryrefslogtreecommitdiff
path: root/src/server.rs
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-03-24 09:14:34 +0200
committerLars Wirzenius <liw@liw.fi>2021-03-24 09:14:34 +0200
commitc970ac8b443b7331610a36720f9b901146d9eed2 (patch)
tree452ff55e993a815da19fb6d5557adb4c36dd85ab /src/server.rs
parent420cc245bbcb29bfb95d5784e64f6a7c85315225 (diff)
downloadobnam2-c970ac8b443b7331610a36720f9b901146d9eed2.tar.gz
refactor(src/server.rs): drop use of anyhow::Result
anyhow is appropriate for applications, not libraries. Use plain Result and the already existing ServerConfigError instead.
Diffstat (limited to 'src/server.rs')
-rw-r--r--src/server.rs15
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());
}