diff --git a/lib/entry/libimagentryannotation/Cargo.toml b/lib/entry/libimagentryannotation/Cargo.toml index 085beed4..506a1213 100644 --- a/lib/entry/libimagentryannotation/Cargo.toml +++ b/lib/entry/libimagentryannotation/Cargo.toml @@ -22,8 +22,9 @@ maintenance = { status = "actively-developed" } [dependencies] lazy_static = "1" toml = "0.4" -toml-query = "0.7" -error-chain = "0.12" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "failure" } +failure = "0.1" +failure_derive = "0.1" libimagstore = { version = "0.9.0", path = "../../../lib/core/libimagstore" } libimagerror = { version = "0.9.0", path = "../../../lib/core/libimagerror" } diff --git a/lib/entry/libimagentryannotation/src/annotateable.rs b/lib/entry/libimagentryannotation/src/annotateable.rs index d38b9c66..c9c6f2d6 100644 --- a/lib/entry/libimagentryannotation/src/annotateable.rs +++ b/lib/entry/libimagentryannotation/src/annotateable.rs @@ -31,9 +31,10 @@ use libimagentryutil::isa::IsKindHeaderPathProvider; use toml_query::read::TomlValueReadTypeExt; use toml_query::insert::TomlValueInsertExt; -use error::Result; -use error::AnnotationErrorKind as AEK; -use error::ResultExt; +use failure::Fallible as Result; +use failure::ResultExt; +use failure::Error; +use failure::err_msg; use iter::*; @@ -52,7 +53,6 @@ impl Annotateable for Entry { fn annotate<'a>(&mut self, store: &'a Store, ann_name: &str) -> Result> { use module_path::ModuleEntryPath; store.retrieve(ModuleEntryPath::new(ann_name).into_storeid()?) - .map_err(From::from) .and_then(|mut anno| { { let _ = anno.set_isflag::()?; @@ -64,7 +64,8 @@ impl Annotateable for Entry { }) .and_then(|mut anno| { anno.add_internal_link(self) - .chain_err(|| AEK::LinkingError) + .context(err_msg("Linking error")) + .map_err(Error::from) .map(|_| anno) }) } @@ -91,13 +92,12 @@ impl Annotateable for Entry { /// Get all annotations of an entry fn annotations<'a>(&self, store: &'a Store) -> Result> { self.get_internal_links() - .map_err(From::from) .map(|iter| StoreIdIterator::new(Box::new(iter.map(|e| e.get_store_id().clone()).map(Ok)))) .map(|i| AnnotationIter::new(i, store)) } fn is_annotation(&self) -> Result { - self.is::().map_err(From::from) + self.is::() } } diff --git a/lib/entry/libimagentryannotation/src/annotation_fetcher.rs b/lib/entry/libimagentryannotation/src/annotation_fetcher.rs index ef98bdfd..854f5038 100644 --- a/lib/entry/libimagentryannotation/src/annotation_fetcher.rs +++ b/lib/entry/libimagentryannotation/src/annotation_fetcher.rs @@ -19,7 +19,7 @@ use libimagstore::store::Store; -use error::Result; +use failure::Fallible as Result; use iter::*; pub trait AnnotationFetcher<'a> { diff --git a/lib/entry/libimagentryannotation/src/error.rs b/lib/entry/libimagentryannotation/src/error.rs deleted file mode 100644 index 1a6c644d..00000000 --- a/lib/entry/libimagentryannotation/src/error.rs +++ /dev/null @@ -1,68 +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 { - AnnotationError, AnnotationErrorKind, ResultExt, Result; - } - - links { - StoreError(::libimagstore::error::StoreError, ::libimagstore::error::StoreErrorKind); - LinkError(::libimagentrylink::error::LinkError, ::libimagentrylink::error::LinkErrorKind); - EntryUtilError(::libimagentryutil::error::EntryUtilError, ::libimagentryutil::error::EntryUtilErrorKind); - } - - foreign_links { - TomlQueryError(::toml_query::error::Error); - } - - errors { - StoreReadError { - description("Store read error") - display("Store read error") - } - - StoreWriteError { - description("Store write error") - display("Store write error") - } - - LinkingError { - description("Error while linking") - display("Error while linking") - } - - HeaderWriteError { - description("Couldn't write Header for annotation") - display("Couldn't write Header for annotation") - } - - HeaderReadError { - description("Couldn't read Header of Entry") - display("Couldn't read Header of Entry") - } - - HeaderTypeError { - description("Header field has unexpected type") - display("Header field has unexpected type") - } - - } -} - diff --git a/lib/entry/libimagentryannotation/src/iter.rs b/lib/entry/libimagentryannotation/src/iter.rs index 9485ba07..977ff0f9 100644 --- a/lib/entry/libimagentryannotation/src/iter.rs +++ b/lib/entry/libimagentryannotation/src/iter.rs @@ -22,11 +22,12 @@ use toml_query::read::TomlValueReadTypeExt; use libimagstore::store::Store; use libimagstore::store::FileLockEntry; use libimagstore::storeid::StoreIdIterator; +use libimagerror::errors::ErrorMsg as EM; -use error::Result; -use error::AnnotationError as AE; -use error::AnnotationErrorKind as AEK; -use error::ResultExt; +use failure::Fallible as Result; +use failure::ResultExt; +use failure::Error; +use failure::err_msg; #[derive(Debug)] pub struct AnnotationIter<'a>(StoreIdIterator, &'a Store); @@ -46,11 +47,20 @@ impl<'a> Iterator for AnnotationIter<'a> { loop { match self.0.next() { None => return None, // iterator consumed - Some(Err(e)) => return Some(Err(e).map_err(AE::from)), + Some(Err(e)) => return Some(Err(e).map_err(Error::from)), Some(Ok(id)) => match self.1.get(id) { - Err(e) => return Some(Err(e).chain_err(|| AEK::StoreReadError)), + Err(e) => { + return Some(Err(e) + .context(err_msg("Store read error")) + .map_err(Error::from)) + }, Ok(Some(entry)) => { - match entry.get_header().read_bool("annotation.is_annotation").chain_err(|| AEK::HeaderReadError) { + match entry + .get_header() + .read_bool("annotation.is_annotation") + .context(EM::EntryHeaderReadError) + .map_err(Error::from) + { Ok(None) => continue, // not an annotation Ok(Some(false)) => continue, Ok(Some(true)) => return Some(Ok(entry)), diff --git a/lib/entry/libimagentryannotation/src/lib.rs b/lib/entry/libimagentryannotation/src/lib.rs index 8c83eae7..cb904135 100644 --- a/lib/entry/libimagentryannotation/src/lib.rs +++ b/lib/entry/libimagentryannotation/src/lib.rs @@ -37,7 +37,7 @@ extern crate toml; extern crate toml_query; -#[macro_use] extern crate error_chain; +extern crate failure; #[macro_use] extern crate libimagstore; extern crate libimagerror; @@ -48,6 +48,5 @@ module_entry_path_mod!("annotations"); pub mod annotateable; pub mod annotation_fetcher; -pub mod error; pub mod iter;