diff --git a/lib/domain/libimagtimetrack/Cargo.toml b/lib/domain/libimagtimetrack/Cargo.toml index ed951391..f5837a26 100644 --- a/lib/domain/libimagtimetrack/Cargo.toml +++ b/lib/domain/libimagtimetrack/Cargo.toml @@ -23,10 +23,10 @@ maintenance = { status = "actively-developed" } filters = "0.3" chrono = "0.4" toml = "0.4" -toml-query = "0.7" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "failure" } lazy_static = "1" is-match = "0.1" -error-chain = "0.12" +failure = "0.1" libimagerror = { version = "0.9.0", path = "../../../lib/core/libimagerror" } libimagstore = { version = "0.9.0", path = "../../../lib/core/libimagstore" } diff --git a/lib/domain/libimagtimetrack/src/error.rs b/lib/domain/libimagtimetrack/src/error.rs deleted file mode 100644 index d494597e..00000000 --- a/lib/domain/libimagtimetrack/src/error.rs +++ /dev/null @@ -1,53 +0,0 @@ -// -// imag - the personal information management suite for the commandline -// Copyright (C) 2015-2018 Matthias Beyer and contributors -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; version -// 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -// - -error_chain! { - types { - TimeTrackError, TimeTrackErrorKind, ResultExt, Result; - } - - links { - StoreError(::libimagstore::error::StoreError, ::libimagstore::error::StoreErrorKind); - DateTimeError(::libimagentrydatetime::error::DateError, ::libimagentrydatetime::error::DateErrorKind); - DatePathError(::libimagentrydatetime::datepath::error::DatePathCompilerError, ::libimagentrydatetime::datepath::error::DatePathCompilerErrorKind); - TomlError(::toml_query::error::Error, ::toml_query::error::ErrorKind); - } - - foreign_links { - ChronoParseError(::chrono::format::ParseError); - } - - errors { - HeaderReadError { - description("Error reading header") - display("Error reading header") - } - - TagFormat { - description("Tag has invalid format") - display("Tag has invalid format") - } - - HeaderFieldTypeError { - description("Type error in header") - display("Type error in header") - } - } -} - diff --git a/lib/domain/libimagtimetrack/src/iter/create.rs b/lib/domain/libimagtimetrack/src/iter/create.rs index d7ffa273..1375d701 100644 --- a/lib/domain/libimagtimetrack/src/iter/create.rs +++ b/lib/domain/libimagtimetrack/src/iter/create.rs @@ -20,9 +20,10 @@ use toml::Value; use toml_query::insert::TomlValueInsertExt; use chrono::naive::NaiveDateTime as NDT; +use failure::Fallible as Result; +use failure::Error; use constants::*; -use error::TimeTrackError as TTE; use iter::storeid::TagStoreIdIter; use iter::setendtime::SetEndTimeIter; @@ -50,7 +51,7 @@ impl<'a> CreateTimeTrackIter<'a> impl<'a> Iterator for CreateTimeTrackIter<'a> { - type Item = Result, TTE>; + type Item = Result>; fn next(&mut self) -> Option { self.inner @@ -59,7 +60,7 @@ impl<'a> Iterator for CreateTimeTrackIter<'a> res.and_then(|(id, starttime)| { self.store .create(id) - .map_err(From::from) + .map_err(Error::from) .and_then(|mut entry| { let v = Value::String(starttime.format(DATE_TIME_FORMAT).to_string()); let _ = entry.get_header_mut().insert(DATE_TIME_START_HEADER_PATH, v)?; diff --git a/lib/domain/libimagtimetrack/src/iter/get.rs b/lib/domain/libimagtimetrack/src/iter/get.rs index 202a87d9..8a4afb28 100644 --- a/lib/domain/libimagtimetrack/src/iter/get.rs +++ b/lib/domain/libimagtimetrack/src/iter/get.rs @@ -19,9 +19,10 @@ use libimagstore::iter::Entries; use libimagstore::store::Store; -use libimagstore::store::Result as StoreResult; use libimagstore::store::FileLockEntry; +use failure::Fallible as Result; + use constants::*; pub struct TimeTrackingsGetIterator<'a>(Entries<'a>, &'a Store); @@ -33,7 +34,7 @@ impl<'a> TimeTrackingsGetIterator<'a> { } impl<'a> Iterator for TimeTrackingsGetIterator<'a> { - type Item = StoreResult>; + type Item = Result>; fn next(&mut self) -> Option { while let Some(next) = self.0.next() { diff --git a/lib/domain/libimagtimetrack/src/iter/setendtime.rs b/lib/domain/libimagtimetrack/src/iter/setendtime.rs index e5706bf3..3d2e4ca1 100644 --- a/lib/domain/libimagtimetrack/src/iter/setendtime.rs +++ b/lib/domain/libimagtimetrack/src/iter/setendtime.rs @@ -20,9 +20,9 @@ use toml::Value; use toml_query::insert::TomlValueInsertExt; use chrono::naive::NaiveDateTime as NDT; +use failure::Fallible as Result; use constants::*; -use error::TimeTrackError as TTE; use iter::create::CreateTimeTrackIter; use libimagstore::store::FileLockEntry; @@ -43,7 +43,7 @@ impl<'a> SetEndTimeIter<'a> } impl<'a> Iterator for SetEndTimeIter<'a> { - type Item = Result, TTE>; + type Item = Result>; fn next(&mut self) -> Option { self.inner diff --git a/lib/domain/libimagtimetrack/src/iter/storeid.rs b/lib/domain/libimagtimetrack/src/iter/storeid.rs index 2932663b..91656a3f 100644 --- a/lib/domain/libimagtimetrack/src/iter/storeid.rs +++ b/lib/domain/libimagtimetrack/src/iter/storeid.rs @@ -18,9 +18,10 @@ // use chrono::naive::NaiveDateTime as NDT; +use failure::Fallible as Result; +use failure::Error; use constants::*; -use error::TimeTrackError; use iter::tag::TagIter; use iter::create::CreateTimeTrackIter; @@ -48,7 +49,7 @@ impl TagStoreIdIter { } impl Iterator for TagStoreIdIter { - type Item = Result<(StoreId, NDT), TimeTrackError>; + type Item = Result<(StoreId, NDT)>; fn next(&mut self) -> Option { use module_path::ModuleEntryPath; @@ -62,7 +63,7 @@ impl Iterator for TagStoreIdIter { let id_str = format!("{}-{}", dt, tag.as_str()); ModuleEntryPath::new(id_str) .into_storeid() - .map_err(From::from) + .map_err(Error::from) .map(|id| (id, self.datetime.clone())) }) }) diff --git a/lib/domain/libimagtimetrack/src/iter/tag.rs b/lib/domain/libimagtimetrack/src/iter/tag.rs index e8589445..3d479a25 100644 --- a/lib/domain/libimagtimetrack/src/iter/tag.rs +++ b/lib/domain/libimagtimetrack/src/iter/tag.rs @@ -18,10 +18,10 @@ // use chrono::naive::NaiveDateTime as NDT; +use failure::Fallible as Result; +use failure::Error; +use failure::err_msg; -use error::TimeTrackError; -use error::TimeTrackErrorKind as TTEK; -use error::TimeTrackError as TTE; use tag::TimeTrackingTag as TTT; use iter::storeid::TagStoreIdIter; @@ -40,7 +40,7 @@ impl TagIter { } impl Iterator for TagIter { - type Item = Result; + type Item = Result; fn next(&mut self) -> Option { self.0 @@ -48,7 +48,7 @@ impl Iterator for TagIter { .map(|t| if is_tag_str(&t).is_ok() { Ok(TTT::from(t)) } else { - Err(TTE::from_kind(TTEK::TagFormat)) + Err(Error::from(err_msg("Error in Tag format"))) }) } } diff --git a/lib/domain/libimagtimetrack/src/lib.rs b/lib/domain/libimagtimetrack/src/lib.rs index 952ac918..37fbbc7b 100644 --- a/lib/domain/libimagtimetrack/src/lib.rs +++ b/lib/domain/libimagtimetrack/src/lib.rs @@ -43,7 +43,7 @@ extern crate toml_query; extern crate lazy_static; #[macro_use] extern crate is_match; -#[macro_use] extern crate error_chain; +extern crate failure; #[macro_use] extern crate libimagstore; @@ -52,7 +52,6 @@ extern crate libimagentrytag; extern crate libimagerror; mod constants; -pub mod error; pub mod timetracking; pub mod timetrackingstore; pub mod iter; diff --git a/lib/domain/libimagtimetrack/src/tag.rs b/lib/domain/libimagtimetrack/src/tag.rs index dfaf9a48..9ee40c68 100644 --- a/lib/domain/libimagtimetrack/src/tag.rs +++ b/lib/domain/libimagtimetrack/src/tag.rs @@ -21,8 +21,10 @@ use std::fmt::Display; use std::fmt::Error as FmtError; use std::fmt::Formatter; use std::path::PathBuf; +use std::result::Result as RResult; + +use failure::Fallible as Result; -use libimagstore::store::Result as StoreResult; use libimagstore::storeid::IntoStoreId; use libimagstore::storeid::StoreId; @@ -38,7 +40,7 @@ impl TimeTrackingTag { } impl Display for TimeTrackingTag { - fn fmt(&self, f: &mut Formatter) -> Result<(), FmtError> { + fn fmt(&self, f: &mut Formatter) -> RResult<(), FmtError> { self.0.fmt(f) } } @@ -62,7 +64,7 @@ impl<'a> From<&'a String> for TimeTrackingTag { } impl IntoStoreId for TimeTrackingTag { - fn into_storeid(self) -> StoreResult { + fn into_storeid(self) -> Result { StoreId::new_baseless(PathBuf::from(self.0)) } } diff --git a/lib/domain/libimagtimetrack/src/timetracking.rs b/lib/domain/libimagtimetrack/src/timetracking.rs index 51e3384c..e39e5c9c 100644 --- a/lib/domain/libimagtimetrack/src/timetracking.rs +++ b/lib/domain/libimagtimetrack/src/timetracking.rs @@ -27,17 +27,17 @@ use chrono::naive::NaiveDateTime; use libimagstore::store::Entry; +use libimagerror::errors::ErrorMsg as EM; use tag::TimeTrackingTag as TTT; -use error::TimeTrackErrorKind as TTEK; -use error::TimeTrackError as TTE; -use error::Result; use constants::*; use toml::Value; use toml_query::delete::TomlValueDeleteExt; use toml_query::insert::TomlValueInsertExt; use toml_query::read::TomlValueReadTypeExt; +use failure::Fallible as Result; +use failure::Error; pub trait TimeTracking { @@ -64,8 +64,8 @@ impl TimeTracking for Entry { fn get_timetrack_tag(&self) -> Result { self.get_header() .read_string(DATE_TIME_TAG_HEADER_PATH) - .map_err(TTE::from)? - .ok_or(TTE::from_kind(TTEK::HeaderReadError)) + .map_err(Error::from)? + .ok_or_else(|| Error::from(EM::EntryHeaderReadError)) .map(Into::into) } @@ -74,21 +74,21 @@ impl TimeTracking for Entry { self.get_header_mut() .insert(DATE_TIME_START_HEADER_PATH, Value::String(s)) - .map_err(From::from) + .map_err(Error::from) .map(|_| ()) } fn get_start_datetime(&self) -> Result> { self.get_header() .read_string(DATE_TIME_START_HEADER_PATH) - .map_err(From::from) + .map_err(Error::from) .and_then(header_value_to_dt) } fn delete_start_datetime(&mut self) -> Result<()> { self.get_header_mut() .delete(DATE_TIME_START_HEADER_PATH) - .map_err(From::from) + .map_err(Error::from) .map(|_| ()) } @@ -97,21 +97,21 @@ impl TimeTracking for Entry { self.get_header_mut() .insert(DATE_TIME_END_HEADER_PATH, Value::String(s)) - .map_err(From::from) + .map_err(Error::from) .map(|_| ()) } fn get_end_datetime(&self) -> Result> { self.get_header() .read_string(DATE_TIME_END_HEADER_PATH) - .map_err(From::from) + .map_err(Error::from) .and_then(header_value_to_dt) } fn delete_end_datetime(&mut self) -> Result<()> { self.get_header_mut() .delete(DATE_TIME_END_HEADER_PATH) - .map_err(From::from) + .map_err(Error::from) .map(|_| ()) } @@ -135,7 +135,7 @@ impl TimeTracking for Entry { fn header_value_to_dt(val: Option) -> Result> { match val { - Some(ref s) => NaiveDateTime::parse_from_str(s, DATE_TIME_FORMAT).map_err(TTE::from).map(Some), + Some(ref s) => NaiveDateTime::parse_from_str(s, DATE_TIME_FORMAT).map_err(Error::from).map(Some), None => Ok(None), } } diff --git a/lib/domain/libimagtimetrack/src/timetrackingstore.rs b/lib/domain/libimagtimetrack/src/timetrackingstore.rs index 72e608ae..1d8b27cd 100644 --- a/lib/domain/libimagtimetrack/src/timetrackingstore.rs +++ b/lib/domain/libimagtimetrack/src/timetrackingstore.rs @@ -25,12 +25,13 @@ use chrono::NaiveDateTime as NDT; use toml::Value; use toml_query::insert::TomlValueInsertExt; +use failure::Fallible as Result; +use failure::Error; use libimagstore::store::Store; use libimagstore::store::FileLockEntry; use libimagentrydatetime::datepath::compiler::DatePathCompiler; -use error::Result; use constants::*; use iter::get::TimeTrackingsGetIterator; @@ -69,24 +70,24 @@ impl<'a> TimeTrackStore<'a> for Store { use std::path::PathBuf; COMPILER.compile(CRATE_NAME, start) - .map_err(From::from) + .map_err(Error::from) .map(|mut id| { id.local_push(PathBuf::from(ts.as_str())); id }) - .and_then(|id| self.create(id).map_err(From::from)) + .and_then(|id| self.create(id)) .and_then(|mut fle| { let v = Value::String(ts.as_str().to_owned()); fle.get_header_mut() .insert(DATE_TIME_TAG_HEADER_PATH, v) - .map_err(From::from) + .map_err(Error::from) .map(|_| fle) }) .and_then(|mut fle| { let v = Value::String(start.format(DATE_TIME_FORMAT).to_string()); fle.get_header_mut() .insert(DATE_TIME_START_HEADER_PATH, v) - .map_err(From::from) + .map_err(Error::from) .map(|_| fle) }) } @@ -97,7 +98,7 @@ impl<'a> TimeTrackStore<'a> for Store { let v = Value::String(end.format(DATE_TIME_FORMAT).to_string()); fle.get_header_mut() .insert(DATE_TIME_END_HEADER_PATH, v) - .map_err(From::from) + .map_err(Error::from) .map(|_| fle) }) }