diff --git a/bin/domain/imag-diary/Cargo.toml b/bin/domain/imag-diary/Cargo.toml index 1e656766..abf7caa0 100644 --- a/bin/domain/imag-diary/Cargo.toml +++ b/bin/domain/imag-diary/Cargo.toml @@ -25,8 +25,9 @@ maintenance = { status = "actively-developed" } chrono = "0.4" log = "0.4.0" toml = "0.4" -toml-query = "0.7" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "failure" } itertools = "0.7" +failure = "0.1" libimagerror = { version = "0.9.0", path = "../../../lib/core/libimagerror" } libimagstore = { version = "0.9.0", path = "../../../lib/core/libimagstore" } diff --git a/bin/domain/imag-diary/src/create.rs b/bin/domain/imag-diary/src/create.rs index 4f861cec..6fb730f8 100644 --- a/bin/domain/imag-diary/src/create.rs +++ b/bin/domain/imag-diary/src/create.rs @@ -21,10 +21,11 @@ use clap::ArgMatches; use chrono::NaiveDateTime; use chrono::Local; use chrono::Timelike; +use failure::Error; +use failure::ResultExt; +use failure::err_msg; use libimagdiary::diary::Diary; -use libimagdiary::error::DiaryErrorKind as DEK; -use libimagdiary::error::ResultExt; use libimagentryedit::edit::Edit; use libimagrt::runtime::Runtime; use libimagerror::trace::MapErrTrace; @@ -47,8 +48,7 @@ pub fn create(rt: &Runtime) { Ok(()) } else { debug!("Editing new diary entry"); - entry.edit_content(rt) - .chain_err(|| DEK::DiaryEditError) + entry.edit_content(rt).context(err_msg("Diary edit error")).map_err(Error::from) }; let _ = res.map_err_trace_exit_unwrap(1); @@ -75,7 +75,9 @@ fn create_entry<'a>(diary: &'a Store, diaryname: &str, rt: &Runtime) -> FileLock }) .map(|timed| { let time = create_id_from_clispec(&create, &diaryname, timed); - diary.new_entry_at(&diaryname, &time).chain_err(|| DEK::StoreWriteError) + diary.new_entry_at(&diaryname, &time) + .context(err_msg("Store write error")) + .map_err(Error::from) }) .unwrap_or_else(|| { debug!("Creating non-timed entry"); diff --git a/bin/domain/imag-diary/src/list.rs b/bin/domain/imag-diary/src/list.rs index a40cd0ff..a1f32ff2 100644 --- a/bin/domain/imag-diary/src/list.rs +++ b/bin/domain/imag-diary/src/list.rs @@ -29,9 +29,10 @@ use libimagerror::exit::ExitUnwrap; use libimagutil::debug_result::*; use libimagdiary::diaryid::DiaryId; use libimagdiary::diaryid::FromStoreId; -use libimagdiary::error::Result; use libimagstore::storeid::IntoStoreId; +use failure::Fallible as Result; + use util::get_diary_name; pub fn list(rt: &Runtime) { diff --git a/bin/domain/imag-diary/src/main.rs b/bin/domain/imag-diary/src/main.rs index d48f0288..73a999b5 100644 --- a/bin/domain/imag-diary/src/main.rs +++ b/bin/domain/imag-diary/src/main.rs @@ -33,6 +33,7 @@ )] #[macro_use] extern crate log; +#[macro_use] extern crate failure; extern crate clap; extern crate chrono; extern crate toml; diff --git a/bin/domain/imag-diary/src/util.rs b/bin/domain/imag-diary/src/util.rs index db56b7ca..f5074ff4 100644 --- a/bin/domain/imag-diary/src/util.rs +++ b/bin/domain/imag-diary/src/util.rs @@ -18,10 +18,13 @@ // use libimagrt::runtime::Runtime; -use libimagdiary::error::*; +use libimagerror::errors::ErrorMsg as EM; use toml::Value; use toml_query::read::TomlValueReadExt; +use failure::Error; +use failure::Fallible as Result; +use failure::ResultExt; pub fn get_diary_name(rt: &Runtime) -> Option { use libimagdiary::config::get_default_diary_name; @@ -58,14 +61,15 @@ pub fn get_diary_timed_config(rt: &Runtime, diary_name: &str) -> Result { let v = cfg .read(&format!("diary.diaries.{}.timed", diary_name)) - .chain_err(|| DiaryErrorKind::IOError); + .context(EM::IO) + .map_err(Error::from); match v { Ok(Some(&Value::String(ref s))) => parse_timed_string(s, diary_name).map(Some), Ok(Some(_)) => { let s = format!("Type error at 'diary.diaryies.{}.timed': should be either 'd'/'daily', 'h'/'hourly', 'm'/'minutely' or 's'/'secondly'", diary_name); - Err(s).map_err(From::from) + Err(format_err!("{}", s)) }, Ok(None) => Ok(None), @@ -87,6 +91,6 @@ pub fn parse_timed_string(s: &str, diary_name: &str) -> Result { } else { let s = format!("Cannot parse config: 'diary.diaries.{}.timed = {}'", diary_name, s); - Err(s).map_err(From::from) + Err(format_err!("{}", s)) } }