From 8278531c9851bc31e6f81a30a907297c79d532d9 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 30 Apr 2019 14:07:43 +0200 Subject: Add top level error printing --- src/main.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1ee2b94..13b42a0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,6 +28,7 @@ use std::io::Cursor; use failure::err_msg; use failure::Error; +use failure::ResultExt; use failure::Fallible as Result; use clap::ArgMatches; use filters::filter::Filter; @@ -91,7 +92,7 @@ fn deserialize_package_list(s: String, filepath: &str) -> Result Result<()> { +fn app() -> Result<()> { let app = cli::build_cli().get_matches(); initialize_logging(&app)?; let config : Configuration = { @@ -110,7 +111,9 @@ fn main() -> Result<()> { let buffer = std::fs::read_to_string(path).map_err(Error::from)?; trace!("Config read into memory"); - toml::de::from_str(&buffer).map_err(Error::from) + toml::de::from_str(&buffer) + .map_err(Error::from) + .context("Configuration file parsing") }?; trace!("Config deserialized"); @@ -210,3 +213,14 @@ fn main() -> Result<()> { Ok(()) } + +fn print_error(e: Error) { + error!("Error: {}", e); + e.iter_causes().for_each(|cause| { + error!("Caused by: {}", cause) + }); +} + +fn main() { + let _ = app().map_err(print_error); +} -- cgit v1.2.3