Add error chaining for compatibility with new libimagerror interface
This commit is contained in:
parent
1f4c0cafe4
commit
ba1c6c06fa
7 changed files with 68 additions and 29 deletions
|
@ -26,6 +26,7 @@ use libimagerror::trace::trace_error;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
use libimagerror::iter::TraceIterator;
|
use libimagerror::iter::TraceIterator;
|
||||||
use libimagstore::store::FileLockEntry;
|
use libimagstore::store::FileLockEntry;
|
||||||
|
use libimagtimetrack::error::TimeTrackError as TTE;
|
||||||
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
||||||
use libimagtimetrack::timetracking::TimeTracking;
|
use libimagtimetrack::timetracking::TimeTracking;
|
||||||
use libimagtimetrack::tag::TimeTrackingTag;
|
use libimagtimetrack::tag::TimeTrackingTag;
|
||||||
|
@ -39,21 +40,25 @@ pub fn day(rt: &Runtime) -> i32 {
|
||||||
let cmd = cmd.unwrap(); // checked in main()
|
let cmd = cmd.unwrap(); // checked in main()
|
||||||
|
|
||||||
let filter = {
|
let filter = {
|
||||||
let start = match cmd.value_of("start").map(::chrono::naive::NaiveDateTime::from_str) {
|
let start = match cmd.value_of("start").map(NaiveDateTime::from_str) {
|
||||||
None => ::chrono::offset::Local::today().and_hms(0, 0, 0).naive_local(),
|
None => ::chrono::offset::Local::today().and_hms(0, 0, 0).naive_local(),
|
||||||
Some(Ok(dt)) => dt,
|
Some(s) => match s.map_err(TTE::from) {
|
||||||
Some(Err(e)) => {
|
Ok(dt) => dt,
|
||||||
trace_error(&e);
|
Err(e) => {
|
||||||
return 1
|
trace_error(&e);
|
||||||
|
return 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let end = match cmd.value_of("end").map(::chrono::naive::NaiveDateTime::from_str) {
|
let end = match cmd.value_of("end").map(NaiveDateTime::from_str) {
|
||||||
None => ::chrono::offset::Local::today().and_hms(23, 59, 59).naive_local(),
|
None => ::chrono::offset::Local::today().and_hms(23, 59, 59).naive_local(),
|
||||||
Some(Ok(dt)) => dt,
|
Some(s) => match s.map_err(TTE::from) {
|
||||||
Some(Err(e)) => {
|
Ok(dt) => dt,
|
||||||
trace_error(&e);
|
Err(e) => {
|
||||||
return 1
|
trace_error(&e);
|
||||||
|
return 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ use libimagerror::trace::trace_error;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
use libimagerror::iter::TraceIterator;
|
use libimagerror::iter::TraceIterator;
|
||||||
use libimagstore::store::FileLockEntry;
|
use libimagstore::store::FileLockEntry;
|
||||||
|
use libimagtimetrack::error::TimeTrackError as TTE;
|
||||||
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
||||||
use libimagtimetrack::timetracking::TimeTracking;
|
use libimagtimetrack::timetracking::TimeTracking;
|
||||||
use libimagtimetrack::tag::TimeTrackingTag;
|
use libimagtimetrack::tag::TimeTrackingTag;
|
||||||
|
@ -44,11 +45,13 @@ pub fn month(rt: &Runtime) -> i32 {
|
||||||
let now = Local::now();
|
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(::chrono::naive::NaiveDateTime::from_str) {
|
||||||
None => NaiveDate::from_ymd(now.year(), now.month(), 1).and_hms(0, 0, 0),
|
None => NaiveDate::from_ymd(now.year(), now.month(), 1).and_hms(0, 0, 0),
|
||||||
Some(Ok(dt)) => dt,
|
Some(s) => match s.map_err(TTE::from) {
|
||||||
Some(Err(e)) => {
|
Ok(dt) => dt,
|
||||||
trace_error(&e);
|
Err(e) => {
|
||||||
return 1
|
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)
|
NaiveDate::from_ymd(year, month, 1).and_hms(0, 0, 0)
|
||||||
},
|
},
|
||||||
Some(Ok(dt)) => dt,
|
Some(s) => match s.map_err(TTE::from) {
|
||||||
Some(Err(e)) => {
|
Ok(dt) => dt,
|
||||||
trace_error(&e);
|
Err(e) => {
|
||||||
return 1
|
trace_error(&e);
|
||||||
|
return 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -19,8 +19,11 @@
|
||||||
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
use chrono::naive::NaiveDateTime;
|
||||||
|
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
use libimagerror::trace::trace_error;
|
use libimagerror::trace::trace_error;
|
||||||
|
use libimagtimetrack::error::TimeTrackError as TTE;
|
||||||
use libimagtimetrack::tag::TimeTrackingTag;
|
use libimagtimetrack::tag::TimeTrackingTag;
|
||||||
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
|
@ -31,7 +34,7 @@ pub fn start(rt: &Runtime) -> i32 {
|
||||||
|
|
||||||
let start = match cmd.value_of("start-time") {
|
let start = match cmd.value_of("start-time") {
|
||||||
None | Some("now") => ::chrono::offset::Local::now().naive_local(),
|
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,
|
Ok(ndt) => ndt,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
trace_error(&e);
|
trace_error(&e);
|
||||||
|
|
|
@ -20,12 +20,14 @@
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use filters::filter::Filter;
|
use filters::filter::Filter;
|
||||||
|
use chrono::NaiveDateTime;
|
||||||
|
|
||||||
use libimagerror::trace::trace_error;
|
use libimagerror::trace::trace_error;
|
||||||
use libimagerror::iter::TraceIterator;
|
use libimagerror::iter::TraceIterator;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
|
|
||||||
|
use libimagtimetrack::error::TimeTrackError as TTE;
|
||||||
use libimagtimetrack::timetracking::TimeTracking;
|
use libimagtimetrack::timetracking::TimeTracking;
|
||||||
use libimagtimetrack::tag::TimeTrackingTag;
|
use libimagtimetrack::tag::TimeTrackingTag;
|
||||||
use libimagtimetrack::timetrackingstore::*;
|
use libimagtimetrack::timetrackingstore::*;
|
||||||
|
@ -40,7 +42,7 @@ pub fn stop(rt: &Runtime) -> i32 {
|
||||||
|
|
||||||
let stop_time = match cmd.value_of("stop-time") {
|
let stop_time = match cmd.value_of("stop-time") {
|
||||||
None | Some("now") => ::chrono::offset::Local::now().naive_local(),
|
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,
|
Ok(ndt) => ndt,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
trace_error(&e);
|
trace_error(&e);
|
||||||
|
|
|
@ -20,10 +20,12 @@
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
|
|
||||||
use clap::ArgMatches;
|
use clap::ArgMatches;
|
||||||
|
use chrono::naive::NaiveDate;
|
||||||
use chrono::naive::NaiveDateTime;
|
use chrono::naive::NaiveDateTime;
|
||||||
|
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
use libimagerror::trace::trace_error;
|
use libimagerror::trace::trace_error;
|
||||||
|
use libimagtimetrack::error::TimeTrackError as TTE;
|
||||||
use libimagtimetrack::tag::TimeTrackingTag;
|
use libimagtimetrack::tag::TimeTrackingTag;
|
||||||
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
|
@ -41,10 +43,10 @@ pub fn track(rt: &Runtime) -> i32 {
|
||||||
match cmd.value_of(clap_name) {
|
match cmd.value_of(clap_name) {
|
||||||
Some("now") => Some(::chrono::offset::Local::now().naive_local()),
|
Some("now") => Some(::chrono::offset::Local::now().naive_local()),
|
||||||
Some(els) => {
|
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),
|
Ok(ndt) => Some(ndt),
|
||||||
Err(e_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)),
|
Ok(ndt) => Some(ndt.and_hms(0, 0, 0)),
|
||||||
Err(e_nd) => {
|
Err(e_nd) => {
|
||||||
error!("Cannot parse date {}:", errname);
|
error!("Cannot parse date {}:", errname);
|
||||||
|
|
|
@ -26,6 +26,7 @@ use libimagerror::trace::trace_error;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
use libimagerror::iter::TraceIterator;
|
use libimagerror::iter::TraceIterator;
|
||||||
use libimagstore::store::FileLockEntry;
|
use libimagstore::store::FileLockEntry;
|
||||||
|
use libimagtimetrack::error::TimeTrackError as TTE;
|
||||||
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
||||||
use libimagtimetrack::timetracking::TimeTracking;
|
use libimagtimetrack::timetracking::TimeTracking;
|
||||||
use libimagtimetrack::tag::TimeTrackingTag;
|
use libimagtimetrack::tag::TimeTrackingTag;
|
||||||
|
@ -44,7 +45,12 @@ pub fn week(rt: &Runtime) -> i32 {
|
||||||
|
|
||||||
let this_week = Local::now().iso_week();
|
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)
|
None => NaiveDate::from_isoywd(this_week.year(), this_week.week(), Weekday::Mon)
|
||||||
.and_hms(0, 0, 0),
|
.and_hms(0, 0, 0),
|
||||||
Some(Ok(dt)) => dt,
|
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)
|
None => NaiveDate::from_isoywd(this_week.year(), this_week.week(), Weekday::Sun)
|
||||||
.and_hms(23, 59, 59),
|
.and_hms(23, 59, 59),
|
||||||
Some(Ok(dt)) => dt,
|
Some(Ok(dt)) => dt,
|
||||||
|
|
|
@ -26,6 +26,7 @@ use libimagerror::trace::trace_error;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
use libimagerror::iter::TraceIterator;
|
use libimagerror::iter::TraceIterator;
|
||||||
use libimagstore::store::FileLockEntry;
|
use libimagstore::store::FileLockEntry;
|
||||||
|
use libimagtimetrack::error::TimeTrackError as TTE;
|
||||||
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
||||||
use libimagtimetrack::timetracking::TimeTracking;
|
use libimagtimetrack::timetracking::TimeTracking;
|
||||||
use libimagtimetrack::tag::TimeTrackingTag;
|
use libimagtimetrack::tag::TimeTrackingTag;
|
||||||
|
@ -43,7 +44,12 @@ pub fn year(rt: &Runtime) -> i32 {
|
||||||
|
|
||||||
let now = Local::now();
|
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),
|
None => NaiveDate::from_ymd(now.year(), 1, 1).and_hms(0, 0, 0),
|
||||||
Some(Ok(dt)) => dt,
|
Some(Ok(dt)) => dt,
|
||||||
Some(Err(e)) => {
|
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 => {
|
None => {
|
||||||
NaiveDate::from_ymd(now.year() + 1, 1, 1).and_hms(0, 0, 0)
|
NaiveDate::from_ymd(now.year() + 1, 1, 1).and_hms(0, 0, 0)
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue