From 262aae39f446b21ad25e7bbdfbda38e7d4c6c26b Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 3 Sep 2017 15:50:54 +0200 Subject: libimagentryannotation: Rewrite error handling --- lib/entry/libimagentryannotation/src/annotateable.rs | 10 +++++----- lib/entry/libimagentryannotation/src/annotation_fetcher.rs | 12 ++++++------ lib/entry/libimagentryannotation/src/error.rs | 10 +++++----- lib/entry/libimagentryannotation/src/lib.rs | 2 +- 4 files changed, 17 insertions(+), 17 deletions(-) (limited to 'lib/entry/libimagentryannotation') diff --git a/lib/entry/libimagentryannotation/src/annotateable.rs b/lib/entry/libimagentryannotation/src/annotateable.rs index 4fb3589a..85f5f89a 100644 --- a/lib/entry/libimagentryannotation/src/annotateable.rs +++ b/lib/entry/libimagentryannotation/src/annotateable.rs @@ -32,7 +32,7 @@ use toml_query::insert::TomlValueInsertExt; use result::Result; use error::AnnotationErrorKind as AEK; -use error::MapErrInto; +use error::ResultExt; pub trait Annotateable { @@ -51,16 +51,16 @@ impl Annotateable for Entry { fn annotate<'a>(&mut self, store: &'a Store, ann_name: &str) -> Result> { store.retrieve(PathBuf::from(ann_name)) - .map_err_into(AEK::StoreWriteError) + .chain_err(|| AEK::StoreWriteError) .and_then(|mut anno| { anno.get_header_mut() .insert("annotation.is_annotation", Value::Boolean(true)) - .map_err_into(AEK::HeaderWriteError) + .chain_err(|| AEK::HeaderWriteError) .map(|_| anno) }) .and_then(|mut anno| { anno.add_internal_link(self) - .map_err_into(AEK::LinkingError) + .chain_err(|| AEK::LinkingError) .map(|_| anno) }) } @@ -68,7 +68,7 @@ impl Annotateable for Entry { fn is_annotation(&self) -> Result { self.get_header() .read("annotation.is_annotation") - .map_err_into(AEK::StoreReadError) + .chain_err(|| AEK::StoreReadError) .and_then(|res| match res { Some(&Value::Boolean(b)) => Ok(b), None => Ok(false), diff --git a/lib/entry/libimagentryannotation/src/annotation_fetcher.rs b/lib/entry/libimagentryannotation/src/annotation_fetcher.rs index 58b27170..c49ce865 100644 --- a/lib/entry/libimagentryannotation/src/annotation_fetcher.rs +++ b/lib/entry/libimagentryannotation/src/annotation_fetcher.rs @@ -26,7 +26,7 @@ use libimagstore::storeid::StoreIdIterator; use result::Result; use error::AnnotationErrorKind as AEK; -use error::MapErrInto; +use error::ResultExt; use self::iter::*; @@ -45,7 +45,7 @@ impl<'a> AnnotationFetcher<'a> for Store { fn all_annotations(&'a self) -> Result> { Note::all_notes(self) .map(|iter| AnnotationIter::new(iter)) - .map_err_into(AEK::StoreReadError) + .chain_err(|| AEK::StoreReadError) } /// Get all annotations (in an iterator) for an entry @@ -57,7 +57,7 @@ impl<'a> AnnotationFetcher<'a> for Store { /// entry, but should normally be not that heavy. fn annotations_for_entry(&'a self, entry: &Entry) -> Result> { entry.get_internal_links() - .map_err_into(AEK::StoreReadError) + .chain_err(|| AEK::StoreReadError) .map(|iter| StoreIdIterator::new(Box::new(iter.map(|e| e.get_store_id().clone())))) .map(|iter| NoteIterator::new(self, iter)) .map(|iter| AnnotationIter::new(iter)) @@ -76,7 +76,7 @@ pub mod iter { use result::Result; use error::AnnotationErrorKind as AEK; - use error::MapErrInto; + use error::ResultExt; #[derive(Debug)] pub struct AnnotationIter<'a>(NoteIterator<'a>); @@ -100,10 +100,10 @@ pub mod iter { Ok(None) => continue, // not an annotation Ok(Some(&Value::Boolean(true))) => return Some(Ok(note)), Ok(Some(_)) => return Some(Err(AEK::HeaderTypeError.into_error())), - Err(e) => return Some(Err(e).map_err_into(AEK::HeaderReadError)), + Err(e) => return Some(Err(e).chain_err(|| AEK::HeaderReadError)), } }, - Some(Err(e)) => return Some(Err(e).map_err_into(AEK::StoreReadError)), + Some(Err(e)) => return Some(Err(e).chain_err(|| AEK::StoreReadError)), None => return None, // iterator consumed } } diff --git a/lib/entry/libimagentryannotation/src/error.rs b/lib/entry/libimagentryannotation/src/error.rs index 6355048e..7543b85a 100644 --- a/lib/entry/libimagentryannotation/src/error.rs +++ b/lib/entry/libimagentryannotation/src/error.rs @@ -17,6 +17,10 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // +use std::error::Error; + +use libimagerror::into::IntoError; + error_chain! { types { AnnotationError, AnnotationErrorKind, ResultExt, Result; @@ -56,10 +60,6 @@ error_chain! { } } -pub use self::error::AnnotationError; -pub use self::error::AnnotationErrorKind; -pub use self::error::MapErrInto; - impl IntoError for AnnotationErrorKind { type Target = AnnotationError; @@ -67,7 +67,7 @@ impl IntoError for AnnotationErrorKind { AnnotationError::from_kind(self) } - fn into_error_with_cause(self, cause: Box) -> Self::Target { + fn into_error_with_cause(self, _: Box) -> Self::Target { AnnotationError::from_kind(self) } } diff --git a/lib/entry/libimagentryannotation/src/lib.rs b/lib/entry/libimagentryannotation/src/lib.rs index e2f9fb51..204e67b3 100644 --- a/lib/entry/libimagentryannotation/src/lib.rs +++ b/lib/entry/libimagentryannotation/src/lib.rs @@ -39,7 +39,7 @@ extern crate toml; extern crate toml_query; #[macro_use] extern crate error_chain; -#[macro_use] extern crate libimagerror; +extern crate libimagerror; extern crate libimagstore; extern crate libimagentrylink; extern crate libimagnotes; -- cgit v1.2.3