imag-diary: Use Err/Ok Result map utils to refactor code

This commit is contained in:
Matthias Beyer 2016-09-06 11:27:30 +02:00
parent 473e6d5b6a
commit a39f07f9a5
2 changed files with 10 additions and 10 deletions

View file

@ -6,7 +6,7 @@ use libimagdiary::error::DiaryErrorKind as DEK;
use libimagdiary::error::MapErrInto;
use libimagentryedit::edit::Edit;
use libimagrt::runtime::Runtime;
use libimagerror::trace::trace_error;
use libimagerror::trace::MapErrTrace;
use libimagerror::into::IntoError;
use libimagtimeui::datetime::DateTime;
use libimagtimeui::parse::Parse;
@ -37,7 +37,7 @@ pub fn edit(rt: &Runtime) {
Some(Err(e)) => Err(e),
None => Err(DEK::EntryNotInDiary.into_error()),
}
.map_err(|e| trace_error(&e)).ok();
.map_err_trace().ok();
}

View file

@ -5,8 +5,9 @@ use libimagentrylist::listers::core::CoreLister;
use libimagentrylist::lister::Lister;
use libimagrt::runtime::Runtime;
use libimagstore::store::Entry;
use libimagerror::trace::trace_error;
use libimagutil::warn_exit::warn_exit;
use libimagerror::trace::MapErrTrace;
use libimagutil::debug_result::*;
use util::get_diary_name;
@ -18,7 +19,7 @@ pub fn list(rt: &Runtime) {
e.get_location().clone()
.without_base()
.to_str()
.map_err(|e| trace_error(&e))
.map_err_trace()
.unwrap_or(String::from("<<Path Parsing Error>>"))
}
@ -28,17 +29,16 @@ pub fn list(rt: &Runtime) {
.and_then(|es| {
debug!("Iterator for listing: {:?}", es);
let es = es.filter_map(|a| {
debug!("Filtering: {:?}", a);
a.ok()
}).map(|e| e.into());
let es = es
.filter_map(|a| a.map_dbg(|e| format!("Filtering: {:?}", e)).ok())
.map(|e| e.into());
CoreLister::new(&entry_to_location_listing_string)
.list(es) // TODO: Do not ignore non-ok()s
.map_err_into(DEK::IOError)
})
.map(|_| debug!("Ok"))
.map_err(|e| trace_error(&e))
.map_dbg_str("Ok")
.map_err_trace()
.ok();
}