imag-timetrack: Move from error-chain to failure

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
Matthias Beyer 2018-10-30 18:40:53 +01:00
parent d7eda6c451
commit fd2367b849
10 changed files with 33 additions and 27 deletions

View file

@ -27,7 +27,8 @@ chrono = "0.4"
filters = "0.3" filters = "0.3"
itertools = "0.7" itertools = "0.7"
prettytable-rs = "0.8" 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" } libimagstore = { version = "0.9.0", path = "../../../lib/core/libimagstore" }
libimagrt = { version = "0.9.0", path = "../../../lib/core/libimagrt" } libimagrt = { version = "0.9.0", path = "../../../lib/core/libimagrt" }

View file

@ -22,13 +22,13 @@ use std::str::FromStr;
use filters::filter::Filter; use filters::filter::Filter;
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use failure::Error;
use libimagerror::trace::trace_error; use libimagerror::trace::trace_error;
use libimagerror::trace::MapErrTrace; use libimagerror::trace::MapErrTrace;
use libimagerror::iter::TraceIterator; use libimagerror::iter::TraceIterator;
use libimagerror::io::ToExitCode; use libimagerror::io::ToExitCode;
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 +44,7 @@ pub fn day(rt: &Runtime) -> i32 {
let filter = { let filter = {
let start = match cmd.value_of("start").map(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(s) => match s.map_err(TTE::from) { Some(s) => match s.map_err(Error::from) {
Ok(dt) => dt, Ok(dt) => dt,
Err(e) => { Err(e) => {
trace_error(&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) { 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(s) => match s.map_err(TTE::from) { Some(s) => match s.map_err(Error::from) {
Ok(dt) => dt, Ok(dt) => dt,
Err(e) => { Err(e) => {
trace_error(&e); trace_error(&e);
@ -91,7 +91,7 @@ pub fn day(rt: &Runtime) -> i32 {
.map_err_trace_exit_unwrap(1) .map_err_trace_exit_unwrap(1)
.trace_unwrap() .trace_unwrap()
.filter(|e| filter.filter(e)) .filter(|e| filter.filter(e))
.map(|e| -> Result<_, TTE> { .map(|e| -> Result<_, Error> {
debug!("Processing {:?}", e.get_location()); debug!("Processing {:?}", e.get_location());
let tag = e.get_timetrack_tag()?; let tag = e.get_timetrack_tag()?;

View file

@ -25,15 +25,17 @@ use prettytable::Cell;
use kairos::parser::Parsed; use kairos::parser::Parsed;
use kairos::parser::parse as kairos_parse; use kairos::parser::parse as kairos_parse;
use clap::ArgMatches; 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::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;
use libimagtimetrack::timetrackingstore::TimeTrackStore; use libimagtimetrack::timetrackingstore::TimeTrackStore;
use libimagtimetrack::timetracking::TimeTracking; use libimagtimetrack::timetracking::TimeTracking;
use libimagtimetrack::error::Result;
use libimagrt::runtime::Runtime; use libimagrt::runtime::Runtime;
@ -63,6 +65,7 @@ pub fn list(rt: &Runtime) -> i32 {
::std::process::exit(1) ::std::process::exit(1)
}, },
Some(Err(e)) => { Some(Err(e)) => {
let e = Error::from(e);
trace_error(&e); trace_error(&e);
::std::process::exit(1) ::std::process::exit(1)
} }
@ -164,7 +167,8 @@ pub fn list_impl(rt: &Runtime,
}) })
.map_err_trace_exit_unwrap(1) .map_err_trace_exit_unwrap(1)
.print(&mut rt.stdout()) .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(|_| 0)
.map_err_trace() .map_err_trace()
.unwrap_or(1) .unwrap_or(1)

View file

@ -41,6 +41,7 @@ extern crate filters;
extern crate itertools; extern crate itertools;
extern crate prettytable; extern crate prettytable;
extern crate kairos; extern crate kairos;
extern crate failure;
extern crate libimagerror; extern crate libimagerror;
extern crate libimagstore; extern crate libimagstore;

View file

@ -22,13 +22,13 @@ use std::str::FromStr;
use filters::filter::Filter; use filters::filter::Filter;
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use failure::Error;
use libimagerror::trace::trace_error; use libimagerror::trace::trace_error;
use libimagerror::trace::MapErrTrace; use libimagerror::trace::MapErrTrace;
use libimagerror::io::ToExitCode; use libimagerror::io::ToExitCode;
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;
@ -48,7 +48,7 @@ pub fn month(rt: &Runtime) -> i32 {
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(s) => match s.map_err(TTE::from) { Some(s) => match s.map_err(Error::from) {
Ok(dt) => dt, Ok(dt) => dt,
Err(e) => { Err(e) => {
trace_error(&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) 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, Ok(dt) => dt,
Err(e) => { Err(e) => {
trace_error(&e); trace_error(&e);
@ -106,7 +106,7 @@ pub fn month(rt: &Runtime) -> i32 {
.map_err_trace_exit_unwrap(1) .map_err_trace_exit_unwrap(1)
.trace_unwrap() .trace_unwrap()
.filter(|e| filter.filter(e)) .filter(|e| filter.filter(e))
.map(|e| -> Result<_, TTE> { .map(|e| -> Result<_, Error> {
debug!("Processing {:?}", e.get_location()); debug!("Processing {:?}", e.get_location());
let tag = e.get_timetrack_tag()?; let tag = e.get_timetrack_tag()?;

View file

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

View file

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

View file

@ -22,10 +22,10 @@ use std::process::exit;
use clap::ArgMatches; use clap::ArgMatches;
use chrono::naive::NaiveDate; use chrono::naive::NaiveDate;
use chrono::naive::NaiveDateTime; use chrono::naive::NaiveDateTime;
use failure::Error;
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;
@ -43,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 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), Ok(ndt) => Some(ndt),
Err(e_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)), 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);

View file

@ -22,13 +22,13 @@ use std::str::FromStr;
use filters::filter::Filter; use filters::filter::Filter;
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use failure::Error;
use libimagerror::trace::trace_error; use libimagerror::trace::trace_error;
use libimagerror::trace::MapErrTrace; use libimagerror::trace::MapErrTrace;
use libimagerror::iter::TraceIterator; use libimagerror::iter::TraceIterator;
use libimagerror::io::ToExitCode; use libimagerror::io::ToExitCode;
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;
@ -50,7 +50,7 @@ pub fn week(rt: &Runtime) -> i32 {
let start = match cmd let start = match cmd
.value_of("start") .value_of("start")
.map(|s| { .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) 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 let end = match cmd
.value_of("end") .value_of("end")
.map(|s| { .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) 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) .map_err_trace_exit_unwrap(1)
.trace_unwrap() .trace_unwrap()
.filter(|e| filter.filter(e)) .filter(|e| filter.filter(e))
.map(|e| -> Result<_, TTE> { .map(|e| -> Result<_, Error> {
debug!("Processing {:?}", e.get_location()); debug!("Processing {:?}", e.get_location());
let tag = e.get_timetrack_tag()?; let tag = e.get_timetrack_tag()?;

View file

@ -22,13 +22,13 @@ use std::str::FromStr;
use filters::filter::Filter; use filters::filter::Filter;
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use failure::Error;
use libimagerror::trace::trace_error; use libimagerror::trace::trace_error;
use libimagerror::trace::MapErrTrace; use libimagerror::trace::MapErrTrace;
use libimagerror::iter::TraceIterator; use libimagerror::iter::TraceIterator;
use libimagerror::io::ToExitCode; use libimagerror::io::ToExitCode;
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;
@ -49,7 +49,7 @@ pub fn year(rt: &Runtime) -> i32 {
let start = match cmd let start = match cmd
.value_of("start") .value_of("start")
.map(|s| { .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), 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 let end = match cmd
.value_of("end") .value_of("end")
.map(|s| { .map(|s| {
::chrono::naive::NaiveDateTime::from_str(s).map_err(TTE::from) ::chrono::naive::NaiveDateTime::from_str(s).map_err(Error::from)
}) })
{ {
None => { None => {
@ -104,7 +104,7 @@ pub fn year(rt: &Runtime) -> i32 {
.map_err_trace_exit_unwrap(1) .map_err_trace_exit_unwrap(1)
.trace_unwrap() .trace_unwrap()
.filter(|e| filter.filter(e)) .filter(|e| filter.filter(e))
.map(|e| -> Result<_, TTE> { .map(|e| -> Result<_, Error> {
debug!("Processing {:?}", e.get_location()); debug!("Processing {:?}", e.get_location());
let tag = e.get_timetrack_tag()?; let tag = e.get_timetrack_tag()?;