summaryrefslogtreecommitdiff
path: root/src/bin/obnam-server.rs
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-03-03 10:44:54 +0200
committerLars Wirzenius <liw@liw.fi>2021-03-03 10:52:57 +0200
commit68340ff02e45198bd0e10eebbca665d2adf23a62 (patch)
treeaecb64a4f7003e599c592c6e6cef491c1700d3a5 /src/bin/obnam-server.rs
parentcb68600fef426841147e322f49b2568ebaf8a8dc (diff)
downloadobnam2-68340ff02e45198bd0e10eebbca665d2adf23a62.tar.gz
feat: in errors about reading a configuration file, include its name
Diffstat (limited to 'src/bin/obnam-server.rs')
-rw-r--r--src/bin/obnam-server.rs15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/bin/obnam-server.rs b/src/bin/obnam-server.rs
index d4513fa..47f2b16 100644
--- a/src/bin/obnam-server.rs
+++ b/src/bin/obnam-server.rs
@@ -1,3 +1,4 @@
+use anyhow::Context;
use bytes::Bytes;
use log::{debug, error, info};
use obnam::chunk::DataChunk;
@@ -9,7 +10,7 @@ use serde::Serialize;
use std::collections::HashMap;
use std::default::Default;
use std::net::{SocketAddr, ToSocketAddrs};
-use std::path::PathBuf;
+use std::path::{Path, PathBuf};
use std::sync::Arc;
use structopt::StructOpt;
use tokio::sync::Mutex;
@@ -28,7 +29,7 @@ async fn main() -> anyhow::Result<()> {
pretty_env_logger::init();
let opt = Opt::from_args();
- let config = Config::read_config(&opt.config).unwrap();
+ let config = load_config(&opt.config)?;
let addresses: Vec<SocketAddr> = config.address.to_socket_addrs()?.collect();
if addresses.is_empty() {
@@ -83,6 +84,16 @@ async fn main() -> anyhow::Result<()> {
Ok(())
}
+fn load_config(filename: &Path) -> Result<Config, anyhow::Error> {
+ let config = Config::read_config(&filename).with_context(|| {
+ format!(
+ "Couldn't read default configuration file {}",
+ filename.display()
+ )
+ })?;
+ Ok(config)
+}
+
pub async fn create_chunk(
store: Arc<Mutex<IndexedStore>>,
meta: String,