imag-diary: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
parent
8fb35b5fe1
commit
4486abed84
5 changed files with 20 additions and 11 deletions
|
@ -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" }
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
)]
|
||||
|
||||
#[macro_use] extern crate log;
|
||||
#[macro_use] extern crate failure;
|
||||
extern crate clap;
|
||||
extern crate chrono;
|
||||
extern crate toml;
|
||||
|
|
|
@ -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<String> {
|
||||
use libimagdiary::config::get_default_diary_name;
|
||||
|
@ -58,14 +61,15 @@ pub fn get_diary_timed_config(rt: &Runtime, diary_name: &str) -> Result<Option<T
|
|||
Some(cfg) => {
|
||||
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<Timed> {
|
|||
} else {
|
||||
let s = format!("Cannot parse config: 'diary.diaries.{}.timed = {}'",
|
||||
diary_name, s);
|
||||
Err(s).map_err(From::from)
|
||||
Err(format_err!("{}", s))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue