From 5a7def4c8ebbabbe0143469b465dac0a6f0766fb Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 30 Oct 2018 18:40:52 +0100 Subject: libimagentryedit: Move from error-chain to failure Signed-off-by: Matthias Beyer --- lib/entry/libimagentryedit/Cargo.toml | 1 + lib/entry/libimagentryedit/src/edit.rs | 29 +++++++++-------- lib/entry/libimagentryedit/src/error.rs | 58 --------------------------------- lib/entry/libimagentryedit/src/lib.rs | 3 +- 4 files changed, 17 insertions(+), 74 deletions(-) delete mode 100644 lib/entry/libimagentryedit/src/error.rs (limited to 'lib/entry') 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 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; -- cgit v1.2.3