From 0b89cd9ff97dfda16348f3ef9679e5d5f221943d Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 28 Aug 2016 14:23:32 +0200 Subject: [PATCH 1/2] Add libimagutil::warn_result::* --- libimagutil/src/lib.rs | 1 + libimagutil/src/warn_result.rs | 9 +++++++++ 2 files changed, 10 insertions(+) create mode 100644 libimagutil/src/warn_result.rs diff --git a/libimagutil/src/lib.rs b/libimagutil/src/lib.rs index 58b9271a..4d561a4d 100644 --- a/libimagutil/src/lib.rs +++ b/libimagutil/src/lib.rs @@ -24,3 +24,4 @@ pub mod ismatch; pub mod iter; pub mod key_value_split; pub mod variants; +pub mod warn_result; diff --git a/libimagutil/src/warn_result.rs b/libimagutil/src/warn_result.rs new file mode 100644 index 00000000..505e9f40 --- /dev/null +++ b/libimagutil/src/warn_result.rs @@ -0,0 +1,9 @@ +generate_result_logging_extension!( + WarnResult, + map_warn, + map_warn_str, + map_warn_err, + map_warn_err_str, + |s| { warn!("{}", s); } +); + From c104e165fd21493cf3284de4673187b8f0420422 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 28 Aug 2016 14:31:10 +0200 Subject: [PATCH 2/2] Fix handle_internal_linking() and add error output in case of Err(_) via libimagutil::warn_result::* --- imag-link/Cargo.toml | 3 +++ imag-link/src/main.rs | 13 ++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/imag-link/Cargo.toml b/imag-link/Cargo.toml index ed215bc5..96615b6c 100644 --- a/imag-link/Cargo.toml +++ b/imag-link/Cargo.toml @@ -23,3 +23,6 @@ path = "../libimagentrylink" [dependencies.libimagerror] path = "../libimagerror" +[dependencies.libimagutil] +path = "../libimagutil" + diff --git a/imag-link/src/main.rs b/imag-link/src/main.rs index a43fb087..ff315be4 100644 --- a/imag-link/src/main.rs +++ b/imag-link/src/main.rs @@ -24,6 +24,7 @@ extern crate libimagentrylink; extern crate libimagrt; extern crate libimagstore; extern crate libimagerror; +extern crate libimagutil; use std::process::exit; use std::ops::Deref; @@ -36,6 +37,7 @@ use libimagstore::store::FileLockEntry; use libimagstore::store::Store; use libimagerror::trace::{trace_error, trace_error_exit}; use libimagentrylink::external::ExternalLinker; +use libimagutil::warn_result::*; use clap::ArgMatches; use url::Url; @@ -77,7 +79,16 @@ fn handle_internal_linking(rt: &Runtime) { Ok(Some(e)) => { e.get_internal_links() .map(|links| { - for (i, link) in links.iter().map(|l| l.to_str().ok()).filter_map(|x| x).enumerate() { + let i = links + .iter() + .filter_map(|l| { + l.to_str() + .map_warn_err(|e| format!("Failed to convert StoreId to string: {:?}", e)) + .ok() + }) + .enumerate(); + + for (i, link) in i { println!("{: <3}: {}", i, link); } })