summaryrefslogtreecommitdiffstats
path: root/lib/entry
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
commit5a7def4c8ebbabbe0143469b465dac0a6f0766fb (patch)
tree4d01365353bb09181346b1d3a35ab18d57108f5d /lib/entry
parent7f04eb2bff5eb184d50e8f66f733674f8eea7d31 (diff)
libimagentryedit: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'lib/entry')
-rw-r--r--lib/entry/libimagentryedit/Cargo.toml1
-rw-r--r--lib/entry/libimagentryedit/src/edit.rs29
-rw-r--r--lib/entry/libimagentryedit/src/error.rs58
-rw-r--r--lib/entry/libimagentryedit/src/lib.rs3
4 files changed, 17 insertions, 74 deletions
diff --git a/lib/entry/libimagentryedit/Cargo.toml b/lib/entry/libimagentryedit/Cargo.toml
index 7ca095ad..726518e5 100644
--- a/lib/entry/libimagentryedit/Cargo.toml
+++ b/lib/entry/libimagentryedit/Cargo.toml
@@ -22,6 +22,7 @@ maintenance = { status = "actively-developed" }
[dependencies]
error-chain = "0.12"
toml = "0.4"
+failure = "0.1"
libimagerror = { version = "0.9.0", path = "../../../lib/core/libimagerror" }
libimagrt = { version = "0.9.0", path = "../../../lib/core/libimagrt" }
diff --git a/lib/entry/libimagentryedit/src/edit.rs b/lib/entry/libimagentryedit/src/edit.rs
index 33af2c2b..021f0814 100644
--- a/lib/entry/libimagentryedit/src/edit.rs
+++ b/lib/entry/libimagentryedit/src/edit.rs
@@ -20,10 +20,12 @@
use libimagrt::runtime::Runtime;
use libimagstore::store::Entry;
-use error::Result;
-use error::EditErrorKind;
-use error::EditError as EE;
-use error::ResultExt;
+use failure::Fallible as Result;
+use failure::Error;
+use failure::ResultExt;
+use failure::err_msg;
+
+use libimagerror::errors::ErrorMsg as EM;
pub trait Edit {
fn edit_content(&mut self, rt: &Runtime) -> Result<()>;
@@ -64,7 +66,7 @@ impl EditHeader for Entry {
fn edit_header_and_content(&mut self, rt: &Runtime) -> Result<()> {
let mut header_and_content = self.to_str()?;
let _ = edit_in_tmpfile(rt, &mut header_and_content)?;
- self.replace_from_buffer(&header_and_content).map_err(EE::from)
+ self.replace_from_buffer(&header_and_content).map_err(Error::from)
}
}
@@ -74,17 +76,16 @@ pub fn edit_in_tmpfile(rt: &Runtime, s: &mut String) -> Result<()> {
let editor = rt
.editor()
- .chain_err(|| EditErrorKind::NoEditor)?
- .ok_or_else(|| EE::from_kind(EditErrorKind::NoEditor))?;
+ .context(err_msg("No editor"))?
+ .ok_or_else(|| Error::from(err_msg("No editor")))?;
edit_in_tmpfile_with_command(editor, s)
- .chain_err(|| EditErrorKind::IOError)
- .and_then(|worked| {
- if !worked {
- Err(EditErrorKind::ProcessExitFailure.into())
- } else {
- Ok(())
- }
+ .context(EM::IO)
+ .map_err(Error::from)
+ .and_then(|worked| if !worked {
+ Err(Error::from(EM::ExternalProcessError))
+ } else {
+ Ok(())
})
}
diff --git a/lib/entry/libimagentryedit/src/error.rs b/lib/entry/libimagentryedit/src/error.rs
deleted file mode 100644
index 039dd0c5..00000000
--- a/lib/entry/libimagentryedit/src/error.rs
+++ /dev/null
@@ -1,58 +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 {
- EditError, EditErrorKind, ResultExt, Result;
- }
-
- links {
- StoreError(::libimagstore::error::StoreError, ::libimagstore::error::StoreErrorKind);
- }
-
- foreign_links {
- TomlSerError(::toml::ser::Error);
- TomlDeserError(::toml::de::Error);
- }
-
-
- errors {
- IOError {
- description("IO Error")
- display("IO Error")
- }
-
- NoEditor {
- description("No editor set")
- display("No editor set")
- }
-
- ProcessExitFailure {
- description("Process did not exit properly")
- display("Process did not exit properly")
- }
-
- InstantiateError {
- description("Instantation error")
- display("Instantation error")
- }
-
- }
-}
-
diff --git a/lib/entry/libimagentryedit/src/lib.rs b/lib/entry/libimagentryedit/src/lib.rs
index 29a09073..6de64153 100644
--- a/lib/entry/libimagentryedit/src/lib.rs
+++ b/lib/entry/libimagentryedit/src/lib.rs
@@ -39,8 +39,7 @@ extern crate libimagerror;
extern crate libimagstore;
extern crate libimagrt;
extern crate libimagutil;
-#[macro_use] extern crate error_chain;
extern crate toml;
+extern crate failure;
pub mod edit;
-pub mod error;