libimagentryannotation: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
parent
a8daeb851d
commit
7357f1c985
6 changed files with 29 additions and 87 deletions
|
@ -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" }
|
||||
|
|
|
@ -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<FileLockEntry<'a>> {
|
||||
use module_path::ModuleEntryPath;
|
||||
store.retrieve(ModuleEntryPath::new(ann_name).into_storeid()?)
|
||||
.map_err(From::from)
|
||||
.and_then(|mut anno| {
|
||||
{
|
||||
let _ = anno.set_isflag::<IsAnnotation>()?;
|
||||
|
@ -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<AnnotationIter<'a>> {
|
||||
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<bool> {
|
||||
self.is::<IsAnnotation>().map_err(From::from)
|
||||
self.is::<IsAnnotation>()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
use libimagstore::store::Store;
|
||||
|
||||
use error::Result;
|
||||
use failure::Fallible as Result;
|
||||
use iter::*;
|
||||
|
||||
pub trait AnnotationFetcher<'a> {
|
||||
|
|
|
@ -1,68 +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 {
|
||||
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")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -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)),
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue