libimagtimetrack: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
parent
3951bc7e5d
commit
57f7a5a682
11 changed files with 45 additions and 93 deletions
|
@ -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" }
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
//
|
||||
// imag - the personal information management suite for the commandline
|
||||
// Copyright (C) 2015-2018 Matthias Beyer <mail@beyermatthias.de> 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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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<FileLockEntry<'a>, TTE>;
|
||||
type Item = Result<FileLockEntry<'a>>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
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)?;
|
||||
|
|
|
@ -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<FileLockEntry<'a>>;
|
||||
type Item = Result<FileLockEntry<'a>>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
while let Some(next) = self.0.next() {
|
||||
|
|
|
@ -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<FileLockEntry<'a>, TTE>;
|
||||
type Item = Result<FileLockEntry<'a>>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
self.inner
|
||||
|
|
|
@ -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<Self::Item> {
|
||||
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()))
|
||||
})
|
||||
})
|
||||
|
|
|
@ -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<TTT, TimeTrackError>;
|
||||
type Item = Result<TTT>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
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")))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<StoreId> {
|
||||
fn into_storeid(self) -> Result<StoreId> {
|
||||
StoreId::new_baseless(PathBuf::from(self.0))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<TTT> {
|
||||
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<Option<NaiveDateTime>> {
|
||||
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<Option<NaiveDateTime>> {
|
||||
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<String>) -> Result<Option<NaiveDateTime>> {
|
||||
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),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue