libimagentryedit: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
parent
7f04eb2bff
commit
5a7def4c8e
4 changed files with 17 additions and 74 deletions
|
@ -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" }
|
||||
|
|
|
@ -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(())
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue