diff options
Diffstat (limited to 'bin/domain/imag-contact/src/util.rs')
-rw-r--r-- | bin/domain/imag-contact/src/util.rs | 41 |
1 files changed, 16 insertions, 25 deletions
diff --git a/bin/domain/imag-contact/src/util.rs b/bin/domain/imag-contact/src/util.rs index 61d061cc..0910f644 100644 --- a/bin/domain/imag-contact/src/util.rs +++ b/bin/domain/imag-contact/src/util.rs @@ -18,14 +18,15 @@ // use std::collections::BTreeMap; -use std::process::exit; + +use failure::Fallible as Result; +use failure::err_msg; +use resiter::IterInnerOkOrElse; +use resiter::AndThen; use libimagcontact::deser::DeserVcard; use libimagcontact::store::ContactStore; use libimagcontact::contact::Contact; -use libimagerror::exit::ExitUnwrap; -use libimagerror::iter::TraceIterator; -use libimagerror::trace::MapErrTrace; use libimagrt::runtime::Runtime; use libimagstore::store::FileLockEntry; @@ -85,34 +86,24 @@ pub fn build_data_object_for_handlebars(i: usize, vcard: &DeserVcard) -> BTreeMa } pub fn find_contact_by_hash<'a, H: AsRef<str>>(rt: &'a Runtime, hash: H) - -> impl Iterator<Item = FileLockEntry<'a>> + -> Result<impl Iterator<Item = Result<(bool, FileLockEntry<'a>)>>> { - rt.store() - .all_contacts() - .map_err_trace_exit_unwrap() + Ok(rt.store() + .all_contacts()? .into_get_iter() - .trace_unwrap_exit() - .map(|o| o.unwrap_or_else(|| { - error!("Failed to get entry"); - exit(1) - })) - .filter(move |entry| { - let deser = entry.deser().map_err_trace_exit_unwrap(); + .map_inner_ok_or_else(|| err_msg("Did not find one entry")) + .and_then_ok(move |entry| { + let deser = entry.deser()?; let id_starts_with_hash = deser.uid() - .ok_or_else(|| { - error!("Could not get StoreId from Store::all_contacts(). This is a BUG!"); - ::std::process::exit(1) - }) - .unwrap() // exited above + .ok_or_else(|| err_msg("Could not get StoreId from Store::all_contacts(). This is a BUG!"))? .starts_with(hash.as_ref()); if id_starts_with_hash { - rt.report_touched(entry.get_location()).unwrap_or_exit(); - true - } else { - false + rt.report_touched(entry.get_location())?; } - }) + + Ok((id_starts_with_hash, entry)) + })) } |