diff --git a/bin/domain/imag-contact/src/create.rs b/bin/domain/imag-contact/src/create.rs index 672ccd17..1d1f6bd4 100644 --- a/bin/domain/imag-contact/src/create.rs +++ b/bin/domain/imag-contact/src/create.rs @@ -18,6 +18,7 @@ // use std::collections::BTreeMap; +use std::error::Error; use std::process::exit; use std::io::Write; use std::io::stdout; @@ -30,10 +31,10 @@ use toml_query::read::TomlValueReadExt; use toml::Value; use uuid::Uuid; +use libimagcontact::error::ContactError as CE; use libimagrt::runtime::Runtime; use libimagerror::trace::MapErrTrace; use libimagerror::trace::trace_error; -use libimagerror::trace::trace_error_exit; use libimagutil::warn_result::WarnResult; use libimagentryref::refstore::RefStore; use libimagentryref::flags::RefFlags; @@ -89,6 +90,8 @@ pub fn create(rt: &Runtime) { .create_new(true) .open(fl.clone()) .map_warn_err_str("Cannot create/open destination File. Stopping.") + .map_err(|e| format!("{}", e.description())) + .map_err(CE::from) .map_err_trace_exit_unwrap(1); (Box::new(file), Some(fl)) @@ -107,7 +110,11 @@ pub fn create(rt: &Runtime) { exit(2); } - match ::toml::de::from_str(&template).map(parse_toml_into_vcard) { + match ::toml::de::from_str(&template) + .map(parse_toml_into_vcard) + .map_err(|e| format!("{}", e.description())) + .map_err(CE::from) + { Err(e) => { error!("Error parsing template"); trace_error(&e); @@ -125,10 +132,10 @@ pub fn create(rt: &Runtime) { } let vcard_string = write_component(&vcard); - if let Err(e) = dest.write_all(&vcard_string.as_bytes()) { - warn!("Error while writing out vcard content"); - trace_error_exit(&e, 1); - } + let _ = dest + .write_all(&vcard_string.as_bytes()) + .map_err(CE::from) + .map_err_trace_exit_unwrap(1); break; } diff --git a/bin/domain/imag-contact/src/main.rs b/bin/domain/imag-contact/src/main.rs index a6c3455d..d6a37607 100644 --- a/bin/domain/imag-contact/src/main.rs +++ b/bin/domain/imag-contact/src/main.rs @@ -52,6 +52,7 @@ extern crate libimagentryedit; use std::process::exit; use std::path::PathBuf; +use std::error::Error; use handlebars::Handlebars; use clap::ArgMatches; @@ -133,6 +134,8 @@ fn list(rt: &Runtime) { let data = build_data_object_for_handlebars(i, hash, &vcard); let s = list_format.render("format", &data) + .map_err(|e| format!("{}", e.description())) + .map_err(CE::from) .map_err_trace_exit_unwrap(1); println!("{}", s); }) @@ -155,7 +158,10 @@ fn import(rt: &Runtime) { .map_err_trace_exit_unwrap(1); } else if path.is_dir() { for entry in WalkDir::new(path).min_depth(1).into_iter() { - let entry = entry.map_err_trace_exit_unwrap(1); + let entry = entry + .map_err(|e| format!("{}", e.description())) + .map_err(CE::from) + .map_err_trace_exit_unwrap(1); if entry.file_type().is_file() { let pb = PathBuf::from(entry.path()); let _ = rt @@ -194,7 +200,11 @@ fn show(rt: &Runtime) { let show_format = get_contact_print_format("contact.show_format", rt, &scmd); let data = build_data_object_for_handlebars(0, hash, &vcard); - let s = show_format.render("format", &data).map_err_trace_exit_unwrap(1); + let s = show_format + .render("format", &data) + .map_err(|e| format!("{}", e.description())) + .map_err(CE::from) + .map_err_trace_exit_unwrap(1); println!("{}", s); } @@ -213,7 +223,11 @@ fn get_contact_print_format(config_value_path: &'static str, rt: &Runtime, scmd: }); let mut hb = Handlebars::new(); - let _ = hb.register_template_string("format", fmt).map_err_trace_exit_unwrap(1); + let _ = hb + .register_template_string("format", fmt) + .map_err(|e| format!("{}", e.description())) + .map_err(CE::from) + .map_err_trace_exit_unwrap(1); hb.register_escape_fn(::handlebars::no_escape); ::libimaginteraction::format::register_all_color_helpers(&mut hb);