diff options
Diffstat (limited to 'lib/domain/libimagcontact/src')
-rw-r--r-- | lib/domain/libimagcontact/src/contact.rs | 10 | ||||
-rw-r--r-- | lib/domain/libimagcontact/src/error.rs | 65 | ||||
-rw-r--r-- | lib/domain/libimagcontact/src/iter.rs | 13 | ||||
-rw-r--r-- | lib/domain/libimagcontact/src/lib.rs | 3 | ||||
-rw-r--r-- | lib/domain/libimagcontact/src/store.rs | 10 | ||||
-rw-r--r-- | lib/domain/libimagcontact/src/util.rs | 2 |
6 files changed, 19 insertions, 84 deletions
diff --git a/lib/domain/libimagcontact/src/contact.rs b/lib/domain/libimagcontact/src/contact.rs index fb586458..7d8eb644 100644 --- a/lib/domain/libimagcontact/src/contact.rs +++ b/lib/domain/libimagcontact/src/contact.rs @@ -20,15 +20,15 @@ use toml::to_string as toml_to_string; use toml::from_str as toml_from_str; use toml_query::read::TomlValueReadExt; +use failure::Fallible as Result; +use failure::Error; use libimagstore::store::Entry; use libimagentryutil::isa::Is; use libimagentryutil::isa::IsKindHeaderPathProvider; +use libimagerror::errors::ErrorMsg as EM; use deser::DeserVcard; -use error::Result; -use error::ContactError as CE; -use error::ContactErrorKind as CEK; /// Trait to be implemented on ::libimagstore::store::Entry pub trait Contact { @@ -48,14 +48,14 @@ provide_kindflag_path!(pub IsContact, "contact.is_contact"); impl Contact for Entry { fn is_contact(&self) -> Result<bool> { - self.is::<IsContact>().map_err(From::from) + self.is::<IsContact>() } fn deser(&self) -> Result<DeserVcard> { let data = self .get_header() .read("contact.data")? - .ok_or_else(|| CE::from_kind(CEK::HeaderDataMissing("contact.data")))?; + .ok_or_else(|| Error::from(EM::EntryHeaderFieldMissing("contact.data")))?; // ugly hack let data_str = toml_to_string(&data)?; diff --git a/lib/domain/libimagcontact/src/error.rs b/lib/domain/libimagcontact/src/error.rs deleted file mode 100644 index 905c5711..00000000 --- a/lib/domain/libimagcontact/src/error.rs +++ /dev/null @@ -1,65 +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 -// - -use libimagstore::storeid::StoreId; - -error_chain! { - types { - ContactError, ContactErrorKind, ResultExt, Result; - } - - links { - StoreError(::libimagstore::error::StoreError, ::libimagstore::error::StoreErrorKind); - VObjectError(::vobject::error::VObjectError, ::vobject::error::VObjectErrorKind); - EntryUtilError(::libimagentryutil::error::EntryUtilError, ::libimagentryutil::error::EntryUtilErrorKind); - } - - foreign_links { - Io(::std::io::Error); - TomlDe(::toml::de::Error); - TomlSer(::toml::ser::Error); - TomlQueryError(::toml_query::error::Error); - UuidError(::uuid::parser::ParseError); - } - - errors { - - HeaderTypeError(ty: &'static str, loc: &'static str) { - description("Type error in header") - display("Type error in header, expected {} at '{}', found other type", ty, loc) - } - - HeaderDataMissing(datapath: &'static str) { - description("Data missing in header") - display("Data missing in header at '{}'", datapath) - } - - EntryNotFound(sid: StoreId) { - description("Entry not found with StoreId") - display("Entry {:?} not found", sid) - } - - UidMissing(buf: String) { - description("Vcard object has no UID") - display("Vcard has no UID : {}", buf) - } - - } -} - diff --git a/lib/domain/libimagcontact/src/iter.rs b/lib/domain/libimagcontact/src/iter.rs index 48f0f403..d175171b 100644 --- a/lib/domain/libimagcontact/src/iter.rs +++ b/lib/domain/libimagcontact/src/iter.rs @@ -20,11 +20,11 @@ use libimagstore::storeid::StoreIdIterator; use libimagstore::store::Store; use libimagstore::store::FileLockEntry; +use libimagerror::errors::ErrorMsg as EM; use contact::Contact; -use error::ContactError as CE; -use error::ContactErrorKind as CEK; -use error::Result; +use failure::Fallible as Result; +use failure::Error; pub struct ContactIter<'a>(StoreIdIterator, &'a Store); @@ -44,11 +44,12 @@ impl<'a> Iterator for ContactIter<'a> { loop { match self.0.next() { None => return None, - Some(Err(e)) => return Some(Err(e).map_err(CE::from)), + Some(Err(e)) => return Some(Err(e).map_err(Error::from)), Some(Ok(sid)) => match self.1.get(sid.clone()).map_err(From::from) { Err(e) => return Some(Err(e)), - Ok(None) => return Some(Err(CE::from_kind(CEK::EntryNotFound(sid)))), - Ok(Some(entry)) => match entry.is_contact().map_err(From::from) { + Ok(None) => return + Some(Err(Error::from(EM::EntryNotFound(sid.local_display_string())))), + Ok(Some(entry)) => match entry.is_contact().map_err(Error::from) { Ok(true) => return Some(Ok(entry)), Ok(false) => continue, Err(e) => return Some(Err(e)), diff --git a/lib/domain/libimagcontact/src/lib.rs b/lib/domain/libimagcontact/src/lib.rs index 87b244e2..7bebea9c 100644 --- a/lib/domain/libimagcontact/src/lib.rs +++ b/lib/domain/libimagcontact/src/lib.rs @@ -36,7 +36,7 @@ #![recursion_limit="128"] #[macro_use] extern crate log; -#[macro_use] extern crate error_chain; +#[macro_use] extern crate failure; extern crate vobject; extern crate toml; extern crate toml_query; @@ -51,7 +51,6 @@ extern crate libimagerror; module_entry_path_mod!("contact"); pub mod contact; -pub mod error; pub mod iter; pub mod store; pub mod deser; diff --git a/lib/domain/libimagcontact/src/store.rs b/lib/domain/libimagcontact/src/store.rs index e2b9aea4..9670454a 100644 --- a/lib/domain/libimagcontact/src/store.rs +++ b/lib/domain/libimagcontact/src/store.rs @@ -24,6 +24,8 @@ use toml::to_string as toml_to_string; use toml::from_str as toml_from_str; use toml_query::insert::TomlValueInsertExt; use vobject::vcard::Vcard; +use failure::Error; +use failure::Fallible as Result; use libimagstore::storeid::IntoStoreId; use libimagstore::storeid::StoreId; @@ -35,9 +37,6 @@ use libimagentryutil::isa::Is; use contact::IsContact; use deser::DeserVcard; use module_path::ModuleEntryPath; -use error::ContactError as CE; -use error::ContactErrorKind as CEK; -use error::Result; use util; pub trait ContactStore<'a> { @@ -95,10 +94,11 @@ impl<'a> ContactStore<'a> for Store { /// /// That means calculating the StoreId and the Value from the vcard data fn prepare_fetching_from_store(buf: &str) -> Result<(StoreId, Value)> { - let vcard = Vcard::build(&buf)?; + let vcard = Vcard::build(&buf).map_err(Error::from)?; debug!("Parsed: {:?}", vcard); - let uid = vcard.uid().ok_or_else(|| CE::from_kind(CEK::UidMissing(buf.to_string())))?; + let uid = vcard.uid() + .ok_or_else(|| Error::from(format_err!("UID Missing: {}", buf.to_string())))?; let value = { // dirty ugly hack let serialized = DeserVcard::from(vcard); diff --git a/lib/domain/libimagcontact/src/util.rs b/lib/domain/libimagcontact/src/util.rs index 53e820c4..e9618574 100644 --- a/lib/domain/libimagcontact/src/util.rs +++ b/lib/domain/libimagcontact/src/util.rs @@ -22,7 +22,7 @@ use std::fmt::Debug; use std::fs::File; use std::io::Read; -use error::Result; +use failure::Fallible as Result; pub fn read_to_string<A: AsRef<Path> + Debug>(pb: A) -> Result<String> { let mut cont = String::new(); |