Add error chaining for compatibility with new libimagerror interface

This commit is contained in:
Matthias Beyer 2018-02-11 19:35:20 +01:00
parent 1f4c0cafe4
commit ba1c6c06fa
7 changed files with 68 additions and 29 deletions

View file

@ -26,6 +26,7 @@ use libimagerror::trace::trace_error;
use libimagerror::trace::MapErrTrace;
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;
@ -39,21 +40,25 @@ pub fn day(rt: &Runtime) -> i32 {
let cmd = cmd.unwrap(); // checked in main()
let filter = {
let start = match cmd.value_of("start").map(::chrono::naive::NaiveDateTime::from_str) {
None => ::chrono::offset::Local::today().and_hms(0, 0, 0).naive_local(),
Some(Ok(dt)) => dt,
Some(Err(e)) => {
trace_error(&e);
return 1
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) {
Ok(dt) => dt,
Err(e) => {
trace_error(&e);
return 1
}
}
};
let end = match cmd.value_of("end").map(::chrono::naive::NaiveDateTime::from_str) {
None => ::chrono::offset::Local::today().and_hms(23, 59, 59).naive_local(),
Some(Ok(dt)) => dt,
Some(Err(e)) => {
trace_error(&e);
return 1
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) {
Ok(dt) => dt,
Err(e) => {
trace_error(&e);
return 1
}
}
};

View file

@ -26,6 +26,7 @@ use libimagerror::trace::trace_error;
use libimagerror::trace::MapErrTrace;
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;
@ -44,11 +45,13 @@ pub fn month(rt: &Runtime) -> i32 {
let now = Local::now();
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(Ok(dt)) => dt,
Some(Err(e)) => {
trace_error(&e);
return 1
None => NaiveDate::from_ymd(now.year(), now.month(), 1).and_hms(0, 0, 0),
Some(s) => match s.map_err(TTE::from) {
Ok(dt) => dt,
Err(e) => {
trace_error(&e);
return 1
}
}
};
@ -65,10 +68,12 @@ pub fn month(rt: &Runtime) -> i32 {
NaiveDate::from_ymd(year, month, 1).and_hms(0, 0, 0)
},
Some(Ok(dt)) => dt,
Some(Err(e)) => {
trace_error(&e);
return 1
Some(s) => match s.map_err(TTE::from) {
Ok(dt) => dt,
Err(e) => {
trace_error(&e);
return 1
}
}
};

View file

@ -19,8 +19,11 @@
use std::str::FromStr;
use chrono::naive::NaiveDateTime;
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;
@ -31,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 ::chrono::naive::NaiveDateTime::from_str(ndt) {
Some(ndt) => match NaiveDateTime::from_str(ndt).map_err(TTE::from) {
Ok(ndt) => ndt,
Err(e) => {
trace_error(&e);

View file

@ -20,12 +20,14 @@
use std::str::FromStr;
use filters::filter::Filter;
use chrono::NaiveDateTime;
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::*;
@ -40,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 ::chrono::naive::NaiveDateTime::from_str(ndt) {
Some(ndt) => match NaiveDateTime::from_str(ndt).map_err(TTE::from) {
Ok(ndt) => ndt,
Err(e) => {
trace_error(&e);

View file

@ -20,10 +20,12 @@
use std::process::exit;
use clap::ArgMatches;
use chrono::naive::NaiveDate;
use chrono::naive::NaiveDateTime;
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;
@ -41,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 ::chrono::naive::NaiveDateTime::parse_from_str(els, DATE_TIME_PARSE_FMT) {
match NaiveDateTime::parse_from_str(els, DATE_TIME_PARSE_FMT).map_err(TTE::from) {
Ok(ndt) => Some(ndt),
Err(e_ndt) => {
match ::chrono::naive::NaiveDate::parse_from_str(els, DATE_PARSE_FMT) {
match NaiveDate::parse_from_str(els, DATE_PARSE_FMT).map_err(TTE::from) {
Ok(ndt) => Some(ndt.and_hms(0, 0, 0)),
Err(e_nd) => {
error!("Cannot parse date {}:", errname);

View file

@ -26,6 +26,7 @@ use libimagerror::trace::trace_error;
use libimagerror::trace::MapErrTrace;
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;
@ -44,7 +45,12 @@ pub fn week(rt: &Runtime) -> i32 {
let this_week = Local::now().iso_week();
let start = match cmd.value_of("start").map(::chrono::naive::NaiveDateTime::from_str) {
let start = match cmd
.value_of("start")
.map(|s| {
::chrono::naive::NaiveDateTime::from_str(s).map_err(TTE::from)
})
{
None => NaiveDate::from_isoywd(this_week.year(), this_week.week(), Weekday::Mon)
.and_hms(0, 0, 0),
Some(Ok(dt)) => dt,
@ -54,7 +60,12 @@ pub fn week(rt: &Runtime) -> i32 {
}
};
let end = match cmd.value_of("end").map(::chrono::naive::NaiveDateTime::from_str) {
let end = match cmd
.value_of("end")
.map(|s| {
::chrono::naive::NaiveDateTime::from_str(s).map_err(TTE::from)
})
{
None => NaiveDate::from_isoywd(this_week.year(), this_week.week(), Weekday::Sun)
.and_hms(23, 59, 59),
Some(Ok(dt)) => dt,

View file

@ -26,6 +26,7 @@ use libimagerror::trace::trace_error;
use libimagerror::trace::MapErrTrace;
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;
@ -43,7 +44,12 @@ pub fn year(rt: &Runtime) -> i32 {
let now = Local::now();
let start = match cmd.value_of("start").map(::chrono::naive::NaiveDateTime::from_str) {
let start = match cmd
.value_of("start")
.map(|s| {
::chrono::naive::NaiveDateTime::from_str(s).map_err(TTE::from)
})
{
None => NaiveDate::from_ymd(now.year(), 1, 1).and_hms(0, 0, 0),
Some(Ok(dt)) => dt,
Some(Err(e)) => {
@ -52,7 +58,12 @@ pub fn year(rt: &Runtime) -> i32 {
}
};
let end = match cmd.value_of("end").map(::chrono::naive::NaiveDateTime::from_str) {
let end = match cmd
.value_of("end")
.map(|s| {
::chrono::naive::NaiveDateTime::from_str(s).map_err(TTE::from)
})
{
None => {
NaiveDate::from_ymd(now.year() + 1, 1, 1).and_hms(0, 0, 0)
},