diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2018-10-30 18:40:51 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2018-10-30 18:46:28 +0100 |
commit | c11e971139f7714c8a58e847266a0978e6ca4841 (patch) | |
tree | 4bfc1bcab7b785f7f6e74d8356339d4aa2790458 /lib | |
parent | a1c65603dc3e622aab661c03fbfe5f0a1eafb6e0 (diff) |
libimagbookmark: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/domain/libimagbookmark/Cargo.toml | 2 | ||||
-rw-r--r-- | lib/domain/libimagbookmark/src/collection.rs | 43 | ||||
-rw-r--r-- | lib/domain/libimagbookmark/src/error.rs | 48 | ||||
-rw-r--r-- | lib/domain/libimagbookmark/src/lib.rs | 3 | ||||
-rw-r--r-- | lib/domain/libimagbookmark/src/link.rs | 10 |
5 files changed, 23 insertions, 83 deletions
diff --git a/lib/domain/libimagbookmark/Cargo.toml b/lib/domain/libimagbookmark/Cargo.toml index e93e7362..c380fe01 100644 --- a/lib/domain/libimagbookmark/Cargo.toml +++ b/lib/domain/libimagbookmark/Cargo.toml @@ -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" } diff --git a/lib/domain/libimagbookmark/src/collection.rs b/lib/domain/libimagbookmark/src/collection.rs index d5e0b2d7..22333690 100644 --- a/lib/domain/libimagbookmark/src/collection.rs +++ b/lib/domain/libimagbookmark/src/collection.rs @@ -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, }; diff --git a/lib/domain/libimagbookmark/src/error.rs b/lib/domain/libimagbookmark/src/error.rs deleted file mode 100644 index 49feefec..00000000 --- a/lib/domain/libimagbookmark/src/error.rs +++ /dev/null @@ -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") - } - - } -} - diff --git a/lib/domain/libimagbookmark/src/lib.rs b/lib/domain/libimagbookmark/src/lib.rs index b1623c01..0e89e20d 100644 --- a/lib/domain/libimagbookmark/src/lib.rs +++ b/lib/domain/libimagbookmark/src/lib.rs @@ -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; diff --git a/lib/domain/libimagbookmark/src/link.rs b/lib/domain/libimagbookmark/src/link.rs index 317e4767..f11035d1 100644 --- a/lib/domain/libimagbookmark/src/link.rs +++ b/lib/domain/libimagbookmark/src/link.rs @@ -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) } } |