summaryrefslogtreecommitdiffstats
path: root/lib/domain
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-10-30 18:40:51 +0100
committerMatthias Beyer <mail@beyermatthias.de>2018-10-30 18:46:29 +0100
commitf4ff2ba250079ca66d58587c7698f7686ac6be74 (patch)
tree25c2174e0a680dd67bb54e0c32601731d2e8a82f /lib/domain
parentd3c082618815df6eb2d3189bb89e641d4ebbcae8 (diff)
libimagmail: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'lib/domain')
-rw-r--r--lib/domain/libimagmail/Cargo.toml2
-rw-r--r--lib/domain/libimagmail/src/error.rs64
-rw-r--r--lib/domain/libimagmail/src/iter.rs2
-rw-r--r--lib/domain/libimagmail/src/lib.rs3
-rw-r--r--lib/domain/libimagmail/src/mail.rs43
5 files changed, 28 insertions, 86 deletions
diff --git a/lib/domain/libimagmail/Cargo.toml b/lib/domain/libimagmail/Cargo.toml
index c52f8d7d..05166d93 100644
--- a/lib/domain/libimagmail/Cargo.toml
+++ b/lib/domain/libimagmail/Cargo.toml
@@ -23,7 +23,7 @@ maintenance = { status = "actively-developed" }
log = "0.4.0"
email = "0.0.20"
filters = "0.3"
-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/libimagmail/src/error.rs b/lib/domain/libimagmail/src/error.rs
deleted file mode 100644
index 519eb729..00000000
--- a/lib/domain/libimagmail/src/error.rs
+++ /dev/null
@@ -1,64 +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 {
- MailError, MailErrorKind, ResultExt, Result;
- }
-
- links {
- RefError(::libimagentryref::error::RefError, ::libimagentryref::error::RefErrorKind);
- }
-
- foreign_links {
- IoError(::std::io::Error);
- }
-
-
- errors {
- RefCreationError {
- description("Error creating a reference to a file/directory")
- display("Error creating a reference to a file/directory")
- }
-
- RefHandlingError {
- description("Error handling a reference")
- display("Error handling a reference")
- }
-
- MailParsingError {
- description("Failed to parse mail")
- display("Failed to parse mail")
- }
-
- FetchByHashError {
- description("Error fetching mail from Store by hash")
- display("Error fetching mail from Store by hash")
- }
- FetchError {
- description("Error fetching mail from Store")
- display("Error fetching mail from Store")
- }
- IOError {
- description("IO Error")
- display("IO Error")
- }
- }
-}
-
diff --git a/lib/domain/libimagmail/src/iter.rs b/lib/domain/libimagmail/src/iter.rs
index 251bc8fb..22fa84bb 100644
--- a/lib/domain/libimagmail/src/iter.rs
+++ b/lib/domain/libimagmail/src/iter.rs
@@ -25,7 +25,7 @@
//!
use mail::Mail;
-use error::Result;
+use failure::Fallible as Result;
use libimagstore::store::FileLockEntry;
diff --git a/lib/domain/libimagmail/src/lib.rs b/lib/domain/libimagmail/src/lib.rs
index 1439f9b7..fc883404 100644
--- a/lib/domain/libimagmail/src/lib.rs
+++ b/lib/domain/libimagmail/src/lib.rs
@@ -38,13 +38,12 @@
#[macro_use] extern crate log;
extern crate email;
extern crate filters;
-#[macro_use] extern crate error_chain;
+extern crate failure;
extern crate libimagerror;
extern crate libimagstore;
extern crate libimagentryref;
-pub mod error;
pub mod iter;
pub mod mail;
diff --git a/lib/domain/libimagmail/src/mail.rs b/lib/domain/libimagmail/src/mail.rs
index bf16c4a6..a1b33a14 100644
--- a/lib/domain/libimagmail/src/mail.rs
+++ b/lib/domain/libimagmail/src/mail.rs
@@ -21,7 +21,6 @@ use std::path::Path;
use std::fs::File;
use std::io::Read;
use std::fs::OpenOptions;
-use std::result::Result as RResult;
use libimagstore::store::Store;
use libimagstore::storeid::StoreId;
@@ -29,24 +28,25 @@ use libimagstore::store::FileLockEntry;
use libimagentryref::reference::Ref;
use libimagentryref::refstore::RefStore;
use libimagentryref::refstore::UniqueRefPathGenerator;
+use libimagerror::errors::ErrorMsg as EM;
use email::MimeMessage;
use email::results::ParsingResult as EmailParsingResult;
-use error::Result;
-use error::{ResultExt, MailError as ME, MailErrorKind as MEK};
+use failure::Fallible as Result;
+use failure::ResultExt;
+use failure::Error;
+use failure::err_msg;
struct UniqueMailRefGenerator;
impl UniqueRefPathGenerator for UniqueMailRefGenerator {
- type Error = ME;
-
/// The collection the `StoreId` should be created for
fn collection() -> &'static str {
"mail"
}
/// A function which should generate a unique string for a Path
- fn unique_hash<A: AsRef<Path>>(path: A) -> RResult<String, Self::Error> {
+ fn unique_hash<A: AsRef<Path>>(path: A) -> Result<String> {
use filters::filter::Filter;
use email::Header;
@@ -59,7 +59,8 @@ impl UniqueRefPathGenerator for UniqueMailRefGenerator {
.read_to_string(&mut s)?;
MimeMessage::parse(&s)
- .chain_err(|| MEK::RefCreationError)
+ .context(err_msg("Error creating ref"))
+ .map_err(Error::from)
.and_then(|mail| {
let has_key = |hdr: &Header, exp: &str| hdr.name == exp;
@@ -73,7 +74,7 @@ impl UniqueRefPathGenerator for UniqueMailRefGenerator {
for hdr in mail.headers.iter().filter(|item| filter.filter(item)) {
let s = hdr
.get_value()
- .chain_err(|| MEK::RefCreationError)?;
+ .context(err_msg("Ref creation error"))?;
v.push(s);
}
@@ -83,7 +84,7 @@ impl UniqueRefPathGenerator for UniqueMailRefGenerator {
}
/// Postprocess the generated `StoreId` object
- fn postprocess_storeid(sid: StoreId) -> RResult<StoreId, Self::Error> {
+ fn postprocess_storeid(sid: StoreId) -> Result<StoreId> {
Ok(sid)
}
}
@@ -113,13 +114,15 @@ impl<'a> Mail<'a> {
.and_then(|reference| {
debug!("Build reference file: {:?}", reference);
reference.get_path()
- .chain_err(|| MEK::RefHandlingError)
- .and_then(|path| File::open(path).chain_err(|| MEK::IOError))
+ .context(err_msg("Ref handling error"))
+ .map_err(Error::from)
+ .and_then(|path| File::open(path).context(EM::IO).map_err(Error::from))
.and_then(|mut file| {
let mut s = String::new();
file.read_to_string(&mut s)
.map(|_| s)
- .chain_err(|| MEK::IOError)
+ .context(EM::IO)
+ .map_err(Error::from)
})
.map(Buffer::from)
.map(|buffer| Mail(reference, buffer))
@@ -130,8 +133,9 @@ impl<'a> Mail<'a> {
pub fn open<S: AsRef<str>>(store: &Store, hash: S) -> Result<Option<Mail>> {
debug!("Opening Mail by Hash");
store.get_ref::<UniqueMailRefGenerator, S>(hash)
- .chain_err(|| MEK::FetchByHashError)
- .chain_err(|| MEK::FetchError)
+ .context(err_msg("Fetch by hash error"))
+ .context(err_msg("Fetch error"))
+ .map_err(Error::from)
.and_then(|o| match o {
Some(r) => Mail::from_fle(r).map(Some),
None => Ok(None),
@@ -141,13 +145,15 @@ impl<'a> Mail<'a> {
/// Implement me as TryFrom as soon as it is stable
pub fn from_fle(fle: FileLockEntry<'a>) -> Result<Mail<'a>> {
fle.get_path()
- .chain_err(|| MEK::RefHandlingError)
- .and_then(|path| File::open(path).chain_err(|| MEK::IOError))
+ .context(err_msg("Ref handling error"))
+ .map_err(Error::from)
+ .and_then(|path| File::open(path).context(EM::IO).map_err(Error::from))
.and_then(|mut file| {
let mut s = String::new();
file.read_to_string(&mut s)
.map(|_| s)
- .chain_err(|| MEK::IOError)
+ .context(EM::IO)
+ .map_err(Error::from)
})
.map(Buffer::from)
.map(|buffer| Mail(fle, buffer))
@@ -157,7 +163,8 @@ impl<'a> Mail<'a> {
debug!("Getting field in mail: {:?}", field);
self.1
.parsed()
- .chain_err(|| MEK::MailParsingError)
+ .context(err_msg("Mail parsing error"))
+ .map_err(Error::from)
.map(|parsed| {
parsed.headers
.iter()