From 432d8139a08aec171939dca0129c4f140c1245f7 Mon Sep 17 00:00:00 2001 From: Martin Hoffmann Date: Sun, 21 Oct 2018 10:00:48 +0200 Subject: [PATCH] Improve missing directory errors. --- src/main.rs | 8 ++++++-- src/repository.rs | 18 ++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 38a8fa5..2a2d79f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,7 +26,7 @@ lazy_static! { static ref CONFIG: Config = Config::create(); } -fn main() -> Result<(), ProcessingError> { +fn main() { let config = &CONFIG; env_logger::Builder::new() @@ -34,11 +34,15 @@ fn main() -> Result<(), ProcessingError> { .format(|buf, record| write!(buf, "{}\n", record.args())) .init(); - if config.mode.is_once() { + let res = if config.mode.is_once() { run_once(config) } else { run_forever(config) + }; + + if let Err(err) = res { + println!("{}\nAborted.", err); } } diff --git a/src/repository.rs b/src/repository.rs index 44c057f..1418c2c 100644 --- a/src/repository.rs +++ b/src/repository.rs @@ -69,10 +69,16 @@ impl Repository { rsync: bool ) -> Result { if let Err(err) = fs::read_dir(&cache_dir) { - return Err(ProcessingError::BadCacheDirectory(err)) + return Err(ProcessingError::BadCacheDirectory( + format!("{}", cache_dir.display()), + err + )) } if let Err(err) = fs::read_dir(&tal_dir) { - return Err(ProcessingError::BadTalDirectory(err)) + return Err(ProcessingError::BadTalDirectory( + format!("{}", tal_dir.display()), + err + )) } Ok(Repository(Arc::new(RepoInner { cache_dir, @@ -718,11 +724,11 @@ fn entry_to_uri_component(entry: &DirEntry) -> Option { #[derive(Debug, Fail)] pub enum ProcessingError { - #[fail(display="failed to open repository cache directory: {}", _0)] - BadCacheDirectory(io::Error), + #[fail(display="failed to open cache directory {}: {}", _0, _1)] + BadCacheDirectory(String, io::Error), - #[fail(display="failed to open trust anchor directory: {}", _0)] - BadTalDirectory(io::Error), + #[fail(display="failed to open trust anchor directory {}: {}", _0, _1)] + BadTalDirectory(String, io::Error), #[fail(display="{}", _0)] Rsync(RsyncError),