imag-timetrack: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
parent
d7eda6c451
commit
fd2367b849
10 changed files with 33 additions and 27 deletions
|
@ -27,7 +27,8 @@ chrono = "0.4"
|
|||
filters = "0.3"
|
||||
itertools = "0.7"
|
||||
prettytable-rs = "0.8"
|
||||
kairos = { git = "https://github.com/matthiasbeyer/kairos", branch = "master" }
|
||||
kairos = { git = "https://github.com/matthiasbeyer/kairos", branch = "failure" }
|
||||
failure = "0.1"
|
||||
|
||||
libimagstore = { version = "0.9.0", path = "../../../lib/core/libimagstore" }
|
||||
libimagrt = { version = "0.9.0", path = "../../../lib/core/libimagrt" }
|
||||
|
|
|
@ -22,13 +22,13 @@ use std::str::FromStr;
|
|||
|
||||
use filters::filter::Filter;
|
||||
use chrono::NaiveDateTime;
|
||||
use failure::Error;
|
||||
|
||||
use libimagerror::trace::trace_error;
|
||||
use libimagerror::trace::MapErrTrace;
|
||||
use libimagerror::iter::TraceIterator;
|
||||
use libimagerror::io::ToExitCode;
|
||||
use libimagstore::store::FileLockEntry;
|
||||
use libimagtimetrack::error::TimeTrackError as TTE;
|
||||
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
||||
use libimagtimetrack::timetracking::TimeTracking;
|
||||
use libimagtimetrack::tag::TimeTrackingTag;
|
||||
|
@ -44,7 +44,7 @@ pub fn day(rt: &Runtime) -> i32 {
|
|||
let filter = {
|
||||
let start = match cmd.value_of("start").map(NaiveDateTime::from_str) {
|
||||
None => ::chrono::offset::Local::today().and_hms(0, 0, 0).naive_local(),
|
||||
Some(s) => match s.map_err(TTE::from) {
|
||||
Some(s) => match s.map_err(Error::from) {
|
||||
Ok(dt) => dt,
|
||||
Err(e) => {
|
||||
trace_error(&e);
|
||||
|
@ -55,7 +55,7 @@ pub fn day(rt: &Runtime) -> i32 {
|
|||
|
||||
let end = match cmd.value_of("end").map(NaiveDateTime::from_str) {
|
||||
None => ::chrono::offset::Local::today().and_hms(23, 59, 59).naive_local(),
|
||||
Some(s) => match s.map_err(TTE::from) {
|
||||
Some(s) => match s.map_err(Error::from) {
|
||||
Ok(dt) => dt,
|
||||
Err(e) => {
|
||||
trace_error(&e);
|
||||
|
@ -91,7 +91,7 @@ pub fn day(rt: &Runtime) -> i32 {
|
|||
.map_err_trace_exit_unwrap(1)
|
||||
.trace_unwrap()
|
||||
.filter(|e| filter.filter(e))
|
||||
.map(|e| -> Result<_, TTE> {
|
||||
.map(|e| -> Result<_, Error> {
|
||||
debug!("Processing {:?}", e.get_location());
|
||||
|
||||
let tag = e.get_timetrack_tag()?;
|
||||
|
|
|
@ -25,15 +25,17 @@ use prettytable::Cell;
|
|||
use kairos::parser::Parsed;
|
||||
use kairos::parser::parse as kairos_parse;
|
||||
use clap::ArgMatches;
|
||||
use failure::Fallible as Result;
|
||||
use failure::ResultExt;
|
||||
use failure::err_msg;
|
||||
use failure::Error;
|
||||
|
||||
use libimagerror::trace::trace_error;
|
||||
use libimagerror::trace::MapErrTrace;
|
||||
use libimagerror::iter::TraceIterator;
|
||||
use libimagstore::store::FileLockEntry;
|
||||
use libimagtimetrack::error::TimeTrackError;
|
||||
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
||||
use libimagtimetrack::timetracking::TimeTracking;
|
||||
use libimagtimetrack::error::Result;
|
||||
|
||||
use libimagrt::runtime::Runtime;
|
||||
|
||||
|
@ -63,6 +65,7 @@ pub fn list(rt: &Runtime) -> i32 {
|
|||
::std::process::exit(1)
|
||||
},
|
||||
Some(Err(e)) => {
|
||||
let e = Error::from(e);
|
||||
trace_error(&e);
|
||||
::std::process::exit(1)
|
||||
}
|
||||
|
@ -164,7 +167,8 @@ pub fn list_impl(rt: &Runtime,
|
|||
})
|
||||
.map_err_trace_exit_unwrap(1)
|
||||
.print(&mut rt.stdout())
|
||||
.map_err(|_| TimeTrackError::from(String::from("Failed printing table")))
|
||||
.context(err_msg("Failed to print table"))
|
||||
.map_err(Error::from)
|
||||
.map(|_| 0)
|
||||
.map_err_trace()
|
||||
.unwrap_or(1)
|
||||
|
|
|
@ -41,6 +41,7 @@ extern crate filters;
|
|||
extern crate itertools;
|
||||
extern crate prettytable;
|
||||
extern crate kairos;
|
||||
extern crate failure;
|
||||
|
||||
extern crate libimagerror;
|
||||
extern crate libimagstore;
|
||||
|
|
|
@ -22,13 +22,13 @@ use std::str::FromStr;
|
|||
|
||||
use filters::filter::Filter;
|
||||
use chrono::NaiveDateTime;
|
||||
use failure::Error;
|
||||
|
||||
use libimagerror::trace::trace_error;
|
||||
use libimagerror::trace::MapErrTrace;
|
||||
use libimagerror::io::ToExitCode;
|
||||
use libimagerror::iter::TraceIterator;
|
||||
use libimagstore::store::FileLockEntry;
|
||||
use libimagtimetrack::error::TimeTrackError as TTE;
|
||||
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
||||
use libimagtimetrack::timetracking::TimeTracking;
|
||||
use libimagtimetrack::tag::TimeTrackingTag;
|
||||
|
@ -48,7 +48,7 @@ pub fn month(rt: &Runtime) -> i32 {
|
|||
|
||||
let start = match cmd.value_of("start").map(::chrono::naive::NaiveDateTime::from_str) {
|
||||
None => NaiveDate::from_ymd(now.year(), now.month(), 1).and_hms(0, 0, 0),
|
||||
Some(s) => match s.map_err(TTE::from) {
|
||||
Some(s) => match s.map_err(Error::from) {
|
||||
Ok(dt) => dt,
|
||||
Err(e) => {
|
||||
trace_error(&e);
|
||||
|
@ -70,7 +70,7 @@ pub fn month(rt: &Runtime) -> i32 {
|
|||
|
||||
NaiveDate::from_ymd(year, month, 1).and_hms(0, 0, 0)
|
||||
},
|
||||
Some(s) => match s.map_err(TTE::from) {
|
||||
Some(s) => match s.map_err(Error::from) {
|
||||
Ok(dt) => dt,
|
||||
Err(e) => {
|
||||
trace_error(&e);
|
||||
|
@ -106,7 +106,7 @@ pub fn month(rt: &Runtime) -> i32 {
|
|||
.map_err_trace_exit_unwrap(1)
|
||||
.trace_unwrap()
|
||||
.filter(|e| filter.filter(e))
|
||||
.map(|e| -> Result<_, TTE> {
|
||||
.map(|e| -> Result<_, Error> {
|
||||
debug!("Processing {:?}", e.get_location());
|
||||
|
||||
let tag = e.get_timetrack_tag()?;
|
||||
|
|
|
@ -20,10 +20,10 @@
|
|||
use std::str::FromStr;
|
||||
|
||||
use chrono::naive::NaiveDateTime;
|
||||
use failure::Error;
|
||||
|
||||
use libimagrt::runtime::Runtime;
|
||||
use libimagerror::trace::trace_error;
|
||||
use libimagtimetrack::error::TimeTrackError as TTE;
|
||||
use libimagtimetrack::tag::TimeTrackingTag;
|
||||
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
||||
use libimagerror::trace::MapErrTrace;
|
||||
|
@ -34,7 +34,7 @@ pub fn start(rt: &Runtime) -> i32 {
|
|||
|
||||
let start = match cmd.value_of("start-time") {
|
||||
None | Some("now") => ::chrono::offset::Local::now().naive_local(),
|
||||
Some(ndt) => match NaiveDateTime::from_str(ndt).map_err(TTE::from) {
|
||||
Some(ndt) => match NaiveDateTime::from_str(ndt).map_err(Error::from) {
|
||||
Ok(ndt) => ndt,
|
||||
Err(e) => {
|
||||
trace_error(&e);
|
||||
|
|
|
@ -21,13 +21,13 @@ use std::str::FromStr;
|
|||
|
||||
use filters::filter::Filter;
|
||||
use chrono::NaiveDateTime;
|
||||
use failure::Error;
|
||||
|
||||
use libimagerror::trace::trace_error;
|
||||
use libimagerror::iter::TraceIterator;
|
||||
use libimagerror::trace::MapErrTrace;
|
||||
use libimagrt::runtime::Runtime;
|
||||
|
||||
use libimagtimetrack::error::TimeTrackError as TTE;
|
||||
use libimagtimetrack::timetracking::TimeTracking;
|
||||
use libimagtimetrack::tag::TimeTrackingTag;
|
||||
use libimagtimetrack::timetrackingstore::*;
|
||||
|
@ -42,7 +42,7 @@ pub fn stop(rt: &Runtime) -> i32 {
|
|||
|
||||
let stop_time = match cmd.value_of("stop-time") {
|
||||
None | Some("now") => ::chrono::offset::Local::now().naive_local(),
|
||||
Some(ndt) => match NaiveDateTime::from_str(ndt).map_err(TTE::from) {
|
||||
Some(ndt) => match NaiveDateTime::from_str(ndt).map_err(Error::from) {
|
||||
Ok(ndt) => ndt,
|
||||
Err(e) => {
|
||||
trace_error(&e);
|
||||
|
|
|
@ -22,10 +22,10 @@ use std::process::exit;
|
|||
use clap::ArgMatches;
|
||||
use chrono::naive::NaiveDate;
|
||||
use chrono::naive::NaiveDateTime;
|
||||
use failure::Error;
|
||||
|
||||
use libimagrt::runtime::Runtime;
|
||||
use libimagerror::trace::trace_error;
|
||||
use libimagtimetrack::error::TimeTrackError as TTE;
|
||||
use libimagtimetrack::tag::TimeTrackingTag;
|
||||
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
||||
use libimagerror::trace::MapErrTrace;
|
||||
|
@ -43,10 +43,10 @@ pub fn track(rt: &Runtime) -> i32 {
|
|||
match cmd.value_of(clap_name) {
|
||||
Some("now") => Some(::chrono::offset::Local::now().naive_local()),
|
||||
Some(els) => {
|
||||
match NaiveDateTime::parse_from_str(els, DATE_TIME_PARSE_FMT).map_err(TTE::from) {
|
||||
match NaiveDateTime::parse_from_str(els, DATE_TIME_PARSE_FMT).map_err(Error::from) {
|
||||
Ok(ndt) => Some(ndt),
|
||||
Err(e_ndt) => {
|
||||
match NaiveDate::parse_from_str(els, DATE_PARSE_FMT).map_err(TTE::from) {
|
||||
match NaiveDate::parse_from_str(els, DATE_PARSE_FMT).map_err(Error::from) {
|
||||
Ok(ndt) => Some(ndt.and_hms(0, 0, 0)),
|
||||
Err(e_nd) => {
|
||||
error!("Cannot parse date {}:", errname);
|
||||
|
|
|
@ -22,13 +22,13 @@ use std::str::FromStr;
|
|||
|
||||
use filters::filter::Filter;
|
||||
use chrono::NaiveDateTime;
|
||||
use failure::Error;
|
||||
|
||||
use libimagerror::trace::trace_error;
|
||||
use libimagerror::trace::MapErrTrace;
|
||||
use libimagerror::iter::TraceIterator;
|
||||
use libimagerror::io::ToExitCode;
|
||||
use libimagstore::store::FileLockEntry;
|
||||
use libimagtimetrack::error::TimeTrackError as TTE;
|
||||
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
||||
use libimagtimetrack::timetracking::TimeTracking;
|
||||
use libimagtimetrack::tag::TimeTrackingTag;
|
||||
|
@ -50,7 +50,7 @@ pub fn week(rt: &Runtime) -> i32 {
|
|||
let start = match cmd
|
||||
.value_of("start")
|
||||
.map(|s| {
|
||||
::chrono::naive::NaiveDateTime::from_str(s).map_err(TTE::from)
|
||||
::chrono::naive::NaiveDateTime::from_str(s).map_err(Error::from)
|
||||
})
|
||||
{
|
||||
None => NaiveDate::from_isoywd(this_week.year(), this_week.week(), Weekday::Mon)
|
||||
|
@ -65,7 +65,7 @@ pub fn week(rt: &Runtime) -> i32 {
|
|||
let end = match cmd
|
||||
.value_of("end")
|
||||
.map(|s| {
|
||||
::chrono::naive::NaiveDateTime::from_str(s).map_err(TTE::from)
|
||||
::chrono::naive::NaiveDateTime::from_str(s).map_err(Error::from)
|
||||
})
|
||||
{
|
||||
None => NaiveDate::from_isoywd(this_week.year(), this_week.week(), Weekday::Sun)
|
||||
|
@ -104,7 +104,7 @@ pub fn week(rt: &Runtime) -> i32 {
|
|||
.map_err_trace_exit_unwrap(1)
|
||||
.trace_unwrap()
|
||||
.filter(|e| filter.filter(e))
|
||||
.map(|e| -> Result<_, TTE> {
|
||||
.map(|e| -> Result<_, Error> {
|
||||
debug!("Processing {:?}", e.get_location());
|
||||
|
||||
let tag = e.get_timetrack_tag()?;
|
||||
|
|
|
@ -22,13 +22,13 @@ use std::str::FromStr;
|
|||
|
||||
use filters::filter::Filter;
|
||||
use chrono::NaiveDateTime;
|
||||
use failure::Error;
|
||||
|
||||
use libimagerror::trace::trace_error;
|
||||
use libimagerror::trace::MapErrTrace;
|
||||
use libimagerror::iter::TraceIterator;
|
||||
use libimagerror::io::ToExitCode;
|
||||
use libimagstore::store::FileLockEntry;
|
||||
use libimagtimetrack::error::TimeTrackError as TTE;
|
||||
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
||||
use libimagtimetrack::timetracking::TimeTracking;
|
||||
use libimagtimetrack::tag::TimeTrackingTag;
|
||||
|
@ -49,7 +49,7 @@ pub fn year(rt: &Runtime) -> i32 {
|
|||
let start = match cmd
|
||||
.value_of("start")
|
||||
.map(|s| {
|
||||
::chrono::naive::NaiveDateTime::from_str(s).map_err(TTE::from)
|
||||
::chrono::naive::NaiveDateTime::from_str(s).map_err(Error::from)
|
||||
})
|
||||
{
|
||||
None => NaiveDate::from_ymd(now.year(), 1, 1).and_hms(0, 0, 0),
|
||||
|
@ -63,7 +63,7 @@ pub fn year(rt: &Runtime) -> i32 {
|
|||
let end = match cmd
|
||||
.value_of("end")
|
||||
.map(|s| {
|
||||
::chrono::naive::NaiveDateTime::from_str(s).map_err(TTE::from)
|
||||
::chrono::naive::NaiveDateTime::from_str(s).map_err(Error::from)
|
||||
})
|
||||
{
|
||||
None => {
|
||||
|
@ -104,7 +104,7 @@ pub fn year(rt: &Runtime) -> i32 {
|
|||
.map_err_trace_exit_unwrap(1)
|
||||
.trace_unwrap()
|
||||
.filter(|e| filter.filter(e))
|
||||
.map(|e| -> Result<_, TTE> {
|
||||
.map(|e| -> Result<_, Error> {
|
||||
debug!("Processing {:?}", e.get_location());
|
||||
|
||||
let tag = e.get_timetrack_tag()?;
|
||||
|
|
Loading…
Reference in a new issue