Refactor imag-diary to use new error handling interface
This commit is contained in:
parent
503b042690
commit
b9800e19e9
3 changed files with 14 additions and 24 deletions
|
@ -25,7 +25,6 @@ use libimagdiary::error::DiaryErrorKind as DEK;
|
|||
use libimagdiary::error::ResultExt;
|
||||
use libimagentryedit::edit::Edit;
|
||||
use libimagrt::runtime::Runtime;
|
||||
use libimagerror::trace::trace_error_exit;
|
||||
use libimagerror::trace::MapErrTrace;
|
||||
use libimagutil::warn_exit::warn_exit;
|
||||
use libimagstore::store::FileLockEntry;
|
||||
|
@ -50,11 +49,8 @@ pub fn create(rt: &Runtime) {
|
|||
.chain_err(|| DEK::DiaryEditError)
|
||||
};
|
||||
|
||||
if let Err(e) = res {
|
||||
trace_error_exit(&e, 1);
|
||||
} else {
|
||||
info!("Ok!");
|
||||
}
|
||||
let _ = res.map_err_trace_exit_unwrap(1);
|
||||
info!("Ok!");
|
||||
}
|
||||
|
||||
fn create_entry<'a>(diary: &'a Store, diaryname: &str, rt: &Runtime) -> FileLockEntry<'a> {
|
||||
|
@ -88,13 +84,10 @@ fn create_entry<'a>(diary: &'a Store, diaryname: &str, rt: &Runtime) -> FileLock
|
|||
}
|
||||
};
|
||||
|
||||
match entry {
|
||||
Err(e) => trace_error_exit(&e, 1),
|
||||
Ok(e) => {
|
||||
debug!("Created: {}", e.get_location());
|
||||
e
|
||||
}
|
||||
}
|
||||
let e = entry.map_err_trace_exit_unwrap(1);
|
||||
|
||||
debug!("Created: {}", e.get_location());
|
||||
e
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -23,11 +23,11 @@ use chrono::naive::NaiveDateTime;
|
|||
|
||||
use libimagdiary::diaryid::DiaryId;
|
||||
use libimagrt::runtime::Runtime;
|
||||
use libimagerror::trace::trace_error_exit;
|
||||
use libimagtimeui::datetime::DateTime;
|
||||
use libimagtimeui::parse::Parse;
|
||||
use libimagutil::warn_exit::warn_exit;
|
||||
use libimagstore::storeid::IntoStoreId;
|
||||
use libimagerror::trace::MapErrTrace;
|
||||
|
||||
use util::get_diary_name;
|
||||
|
||||
|
@ -53,9 +53,9 @@ pub fn delete(rt: &Runtime) {
|
|||
DiaryId::from_datetime(diaryname.clone(), dt)
|
||||
.into_storeid()
|
||||
.map(|id| rt.store().retrieve(id))
|
||||
.unwrap_or_else(|e| trace_error_exit(&e, 1))
|
||||
.map_err_trace_exit_unwrap(1)
|
||||
})
|
||||
.unwrap_or_else(|e| trace_error_exit(&e, 1))
|
||||
.map_err_trace_exit_unwrap(1)
|
||||
.get_location()
|
||||
.clone();
|
||||
|
||||
|
@ -64,9 +64,10 @@ pub fn delete(rt: &Runtime) {
|
|||
return;
|
||||
}
|
||||
|
||||
if let Err(e) = rt.store().delete(to_del_location) {
|
||||
trace_error_exit(&e, 1)
|
||||
}
|
||||
let _ = rt
|
||||
.store()
|
||||
.delete(to_del_location)
|
||||
.map_err_trace_exit_unwrap(1);
|
||||
|
||||
info!("Ok!");
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@ use libimagerror::trace::MapErrTrace;
|
|||
use libimagtimeui::datetime::DateTime;
|
||||
use libimagtimeui::parse::Parse;
|
||||
use libimagutil::warn_exit::warn_exit;
|
||||
use libimagerror::trace::trace_error_exit;
|
||||
|
||||
use util::get_diary_name;
|
||||
|
||||
|
@ -49,10 +48,7 @@ pub fn edit(rt: &Runtime) {
|
|||
.or_else(|| {
|
||||
rt.store()
|
||||
.get_youngest_entry_id(&diaryname)
|
||||
.map(|optid| match optid {
|
||||
Ok(id) => id,
|
||||
Err(e) => trace_error_exit(&e, 1),
|
||||
})
|
||||
.map(|o| o.map_err_trace_exit_unwrap(1))
|
||||
})
|
||||
.ok_or_else(|| {
|
||||
error!("No entries in diary. Aborting");
|
||||
|
|
Loading…
Reference in a new issue