summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@atos.net>2019-04-30 14:07:43 +0200
committerMatthias Beyer <matthias.beyer@atos.net>2019-04-30 14:07:43 +0200
commit8278531c9851bc31e6f81a30a907297c79d532d9 (patch)
tree0133b9359c6c8c3a3b3a2b9e4a63ea090ba7c52f
parent77f8ed46dc3511e354e42c23976097c87c707024 (diff)
Add top level error printing
-rw-r--r--src/main.rs18
1 files 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<Vec<ComparePack
}
}
-fn main() -> 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);
+}