libimagbookmark: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
parent
a1c65603dc
commit
c11e971139
5 changed files with 23 additions and 83 deletions
|
@ -22,7 +22,7 @@ maintenance = { status = "actively-developed" }
|
|||
[dependencies]
|
||||
url = "1.5"
|
||||
regex = "1"
|
||||
error-chain = "0.12"
|
||||
failure = "0.1"
|
||||
|
||||
libimagstore = { version = "0.9.0", path = "../../../lib/core/libimagstore" }
|
||||
libimagerror = { version = "0.9.0", path = "../../../lib/core/libimagerror" }
|
||||
|
|
|
@ -26,7 +26,8 @@
|
|||
|
||||
use regex::Regex;
|
||||
|
||||
use error::Result;
|
||||
use failure::Fallible as Result;
|
||||
use failure::Error;
|
||||
use module_path::ModuleEntryPath;
|
||||
|
||||
use libimagstore::store::Store;
|
||||
|
@ -53,22 +54,22 @@ impl<'a> BookmarkCollectionStore<'a> for Store {
|
|||
fn new(&'a self, name: &str) -> Result<FileLockEntry<'a>> {
|
||||
ModuleEntryPath::new(name)
|
||||
.into_storeid()
|
||||
.and_then(|id| self.create(id).map_err(From::from))
|
||||
.map_err(From::from)
|
||||
.and_then(|id| self.create(id).map_err(Error::from))
|
||||
.map_err(Error::from)
|
||||
}
|
||||
|
||||
fn get(&'a self, name: &str) -> Result<Option<FileLockEntry<'a>>> {
|
||||
ModuleEntryPath::new(name)
|
||||
.into_storeid()
|
||||
.and_then(|id| self.get(id).map_err(From::from))
|
||||
.map_err(From::from)
|
||||
.and_then(|id| self.get(id).map_err(Error::from))
|
||||
.map_err(Error::from)
|
||||
}
|
||||
|
||||
fn delete(&'a self, name: &str) -> Result<()> {
|
||||
ModuleEntryPath::new(name)
|
||||
.into_storeid()
|
||||
.and_then(|id| self.delete(id).map_err(From::from))
|
||||
.map_err(From::from)
|
||||
.and_then(|id| self.delete(id).map_err(Error::from))
|
||||
.map_err(Error::from)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -84,47 +85,35 @@ pub trait BookmarkCollection : Sized + InternalLinker + ExternalLinker {
|
|||
impl BookmarkCollection for Entry {
|
||||
|
||||
fn links<'a>(&self, store: &'a Store) -> Result<UrlIter<'a>> {
|
||||
self.get_external_links(store).map_err(From::from)
|
||||
self.get_external_links(store)
|
||||
}
|
||||
|
||||
fn link_entries(&self) -> Result<Vec<StoreLink>> {
|
||||
use libimagentrylink::external::is_external_link_storeid;
|
||||
|
||||
self.get_internal_links()
|
||||
.map(|v| v.filter(|id| is_external_link_storeid(id)).collect())
|
||||
.map_err(From::from)
|
||||
self.get_internal_links().map(|v| v.filter(|id| is_external_link_storeid(id)).collect())
|
||||
}
|
||||
|
||||
fn add_link(&mut self, store: &Store, l: Link) -> Result<()> {
|
||||
use link::IntoUrl;
|
||||
|
||||
l.into_url()
|
||||
.and_then(|url| self.add_external_link(store, url).map_err(From::from))
|
||||
.map_err(From::from)
|
||||
l.into_url().and_then(|url| self.add_external_link(store, url))
|
||||
}
|
||||
|
||||
fn get_links_matching<'a>(&self, store: &'a Store, r: Regex) -> Result<LinksMatchingRegexIter<'a>> {
|
||||
use self::iter::IntoLinksMatchingRegexIter;
|
||||
|
||||
self.get_external_links(store)
|
||||
.map(|iter| iter.matching_regex(r))
|
||||
.map_err(From::from)
|
||||
self.get_external_links(store).map(|iter| iter.matching_regex(r))
|
||||
}
|
||||
|
||||
fn remove_link(&mut self, store: &Store, l: Link) -> Result<()> {
|
||||
use link::IntoUrl;
|
||||
|
||||
l.into_url()
|
||||
.and_then(|url| self.remove_external_link(store, url).map_err(From::from))
|
||||
.map_err(From::from)
|
||||
l.into_url().and_then(|url| self.remove_external_link(store, url))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub mod iter {
|
||||
use link::Link;
|
||||
use error::Result;
|
||||
use error::BookmarkError as BE;
|
||||
use failure::Fallible as Result;
|
||||
use failure::Error;
|
||||
|
||||
pub struct LinkIter<I>(I)
|
||||
where I: Iterator<Item = Link>;
|
||||
|
@ -167,7 +156,7 @@ pub mod iter {
|
|||
loop {
|
||||
let n = match self.0.next() {
|
||||
Some(Ok(n)) => n,
|
||||
Some(Err(e)) => return Some(Err(BE::from(e))),
|
||||
Some(Err(e)) => return Some(Err(Error::from(e))),
|
||||
None => return None,
|
||||
};
|
||||
|
||||
|
|
|
@ -1,48 +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 {
|
||||
BookmarkError, BookmarkErrorKind, ResultExt, Result;
|
||||
}
|
||||
|
||||
links {
|
||||
StoreError(::libimagstore::error::StoreError, ::libimagstore::error::StoreErrorKind);
|
||||
LinkError(::libimagentrylink::error::LinkError, ::libimagentrylink::error::LinkErrorKind);
|
||||
}
|
||||
|
||||
errors {
|
||||
LinkParsingError {
|
||||
description("Link parsing error")
|
||||
display("Link parsing error")
|
||||
}
|
||||
|
||||
LinkingError {
|
||||
description("Error while linking")
|
||||
display("Error while linking")
|
||||
}
|
||||
|
||||
CollectionNotFound {
|
||||
description("Link-Collection not found")
|
||||
display("Link-Collection not found")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
extern crate url;
|
||||
extern crate regex;
|
||||
#[macro_use] extern crate error_chain;
|
||||
extern crate failure;
|
||||
|
||||
#[macro_use] extern crate libimagstore;
|
||||
extern crate libimagerror;
|
||||
|
@ -46,5 +46,4 @@ extern crate libimagentrylink;
|
|||
module_entry_path_mod!("bookmark");
|
||||
|
||||
pub mod collection;
|
||||
pub mod error;
|
||||
pub mod link;
|
||||
|
|
|
@ -19,7 +19,10 @@
|
|||
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
use error::Result;
|
||||
use failure::Fallible as Result;
|
||||
use failure::ResultExt;
|
||||
use failure::Error;
|
||||
use failure::err_msg;
|
||||
|
||||
use url::Url;
|
||||
|
||||
|
@ -66,10 +69,7 @@ pub trait IntoUrl {
|
|||
impl IntoUrl for Link {
|
||||
|
||||
fn into_url(self) -> Result<Url> {
|
||||
use error::BookmarkErrorKind as BEK;
|
||||
use error::ResultExt;
|
||||
|
||||
Url::parse(&self[..]).chain_err(|| BEK::LinkParsingError)
|
||||
Url::parse(&self[..]).context(err_msg("Link parsing error")).map_err(Error::from)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue