summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-10-30 18:40:52 +0100
committerMatthias Beyer <mail@beyermatthias.de>2018-10-30 18:46:28 +0100
commit0cbc6741a74430bbc5df16e2f3cead6585cc139b (patch)
tree6812167a5527b380f9453541a9ebf15edc8ae3e8
parent32e8c43ccbc0f58629babc6a4505d2d1c588e0bc (diff)
downloadimag-0cbc6741a74430bbc5df16e2f3cead6585cc139b.zip
imag-0cbc6741a74430bbc5df16e2f3cead6585cc139b.tar.gz
libimagentrytag: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--lib/entry/libimagentrytag/Cargo.toml4
-rw-r--r--lib/entry/libimagentrytag/src/error.rs48
-rw-r--r--lib/entry/libimagentrytag/src/lib.rs3
-rw-r--r--lib/entry/libimagentrytag/src/tag.rs2
-rw-r--r--lib/entry/libimagentrytag/src/tagable.rs43
5 files changed, 29 insertions, 71 deletions
diff --git a/lib/entry/libimagentrytag/Cargo.toml b/lib/entry/libimagentrytag/Cargo.toml
index 43ad925..afc743a 100644
--- a/lib/entry/libimagentrytag/Cargo.toml
+++ b/lib/entry/libimagentrytag/Cargo.toml
@@ -26,8 +26,8 @@ toml = "0.4"
itertools = "0.7"
is-match = "0.1"
filters = "0.3"
-toml-query = "0.7"
-error-chain = "0.12"
+toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "failure" }
+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/entry/libimagentrytag/src/error.rs b/lib/entry/libimagentrytag/src/error.rs
deleted file mode 100644
index 4652416..0000000
--- a/lib/entry/libimagentrytag/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 {
- TagError, TagErrorKind, ResultExt, Result;
- }
-
- errors {
- TagTypeError {
- description("Entry Header Tag Type wrong")
- display("Entry Header Tag Type wrong")
- }
-
- HeaderReadError {
- description("Error while reading entry header")
- display("Error while reading entry header")
- }
-
- HeaderWriteError {
- description("Error while writing entry header")
- display("Error while writing entry header")
- }
-
- NotATag {
- description("String is not a tag")
- display("String is not a tag")
- }
-
- }
-}
-
diff --git a/lib/entry/libimagentrytag/src/lib.rs b/lib/entry/libimagentrytag/src/lib.rs
index 6cfe7c8..6d5f46e 100644
--- a/lib/entry/libimagentrytag/src/lib.rs
+++ b/lib/entry/libimagentrytag/src/lib.rs
@@ -43,12 +43,11 @@ extern crate toml;
extern crate toml_query;
#[macro_use] extern crate is_match;
extern crate filters;
-#[macro_use] extern crate error_chain;
+#[macro_use] extern crate failure;
extern crate libimagstore;
extern crate libimagerror;
-pub mod error;
pub mod tag;
pub mod tagable;
diff --git a/lib/entry/libimagentrytag/src/tag.rs b/lib/entry/libimagentrytag/src/tag.rs
index a2a84a9..ac51d88 100644
--- a/lib/entry/libimagentrytag/src/tag.rs
+++ b/lib/entry/libimagentrytag/src/tag.rs
@@ -17,6 +17,8 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
+use std::result::Result;
+
use regex::Regex;
pub type Tag = String;
diff --git a/lib/entry/libimagentrytag/src/tagable.rs b/lib/entry/libimagentrytag/src/tagable.rs
index e405e51..ed688d5 100644
--- a/lib/entry/libimagentrytag/src/tagable.rs
+++ b/lib/entry/libimagentrytag/src/tagable.rs
@@ -20,14 +20,15 @@
use itertools::Itertools;
use libimagstore::store::Entry;
+use libimagerror::errors::ErrorMsg as EM;
use toml_query::read::TomlValueReadExt;
use toml_query::insert::TomlValueInsertExt;
-use error::TagErrorKind;
-use error::TagError as TE;
-use error::ResultExt;
-use error::Result;
+use failure::Error;
+use failure::ResultExt;
+use failure::Fallible as Result;
+use failure::err_msg;
use tag::{Tag, TagSlice};
use tag::is_tag_str;
@@ -50,23 +51,22 @@ impl Tagable for Value {
fn get_tags(&self) -> Result<Vec<Tag>> {
self.read("tag.values")
- .chain_err(|| TagErrorKind::HeaderReadError)?
+ .map_err(Error::from)
+ .context(EM::EntryHeaderReadError)?
.map(|val| {
debug!("Got Value of tags...");
val.as_array()
.map(|tags| {
debug!("Got Array<T> of tags...");
if !tags.iter().all(|t| is_match!(*t, Value::String(_))) {
- debug!("Got Array<T>, T != String of tags: {:?}", tags);
- return Err(TagErrorKind::TagTypeError.into());
+ return Err(format_err!("Tag type error: Got Array<T> where T is not a String: {:?}", tags));
}
debug!("Got Array<String> of tags...");
if tags.iter().any(|t| match *t {
Value::String(ref s) => !is_tag_str(s).is_ok(),
_ => unreachable!()})
{
- debug!("At least one tag is not a valid tag string");
- return Err(TagErrorKind::NotATag.into());
+ return Err(format_err!("At least one tag is not a valid tag string"));
}
Ok(tags.iter()
@@ -86,21 +86,23 @@ impl Tagable for Value {
fn set_tags(&mut self, ts: &[Tag]) -> Result<()> {
if ts.iter().any(|tag| !is_tag_str(tag).is_ok()) {
- debug!("Not a tag: '{}'", ts.iter().filter(|t| !is_tag_str(t).is_ok()).next().unwrap());
- return Err(TagErrorKind::NotATag.into());
+ let not_tag = ts.iter().filter(|t| !is_tag_str(t).is_ok()).next().unwrap();
+ return Err(format_err!("Not a tag: '{}'", not_tag));
}
let a = ts.iter().unique().map(|t| Value::String(t.clone())).collect();
debug!("Setting tags = {:?}", a);
self.insert("tag.values", Value::Array(a))
.map(|_| ())
- .chain_err(|| TagErrorKind::HeaderWriteError)
+ .map_err(|_| Error::from(EM::EntryHeaderWriteError))
}
fn add_tag(&mut self, t: Tag) -> Result<()> {
- if !is_tag_str(&t).map(|_| true).map_err(|_| TE::from_kind(TagErrorKind::NotATag))? {
- debug!("Not a tag: '{}'", t);
- return Err(TagErrorKind::NotATag.into());
+ if !is_tag_str(&t).map(|_| true)
+ .map_err(|s| format_err!("{}", s))
+ .context(err_msg("Not a tag"))?
+ {
+ return Err(format_err!("Not a tag: '{}'", t));
}
self.get_tags()
@@ -113,9 +115,12 @@ impl Tagable for Value {
}
fn remove_tag(&mut self, t: Tag) -> Result<()> {
- if !is_tag_str(&t).map(|_| true).map_err(|_| TE::from_kind(TagErrorKind::NotATag))? {
+ if !is_tag_str(&t).map(|_| true)
+ .map_err(|s| format_err!("{}", s))
+ .context(err_msg("Not a tag"))?
+ {
debug!("Not a tag: '{}'", t);
- return Err(TagErrorKind::NotATag.into());
+ return Err(format_err!("Not a tag: '{}'", t));
}
self.get_tags()
@@ -127,10 +132,10 @@ impl Tagable for Value {
}
fn has_tag(&self, t: TagSlice) -> Result<bool> {
- let tags = self.read("tag.values").chain_err(|| TagErrorKind::HeaderReadError)?;
+ let tags = self.read("tag.values").context(EM::EntryHeaderReadError)?;
if !tags.iter().all(|t| is_match!(*t, &Value::String(_))) {
- return Err(TagErrorKind::TagTypeError.into());
+ return Err(err_msg("Tag type error"))
}
Ok(tags