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]
|
[dependencies]
|
||||||
error-chain = "0.12"
|
error-chain = "0.12"
|
||||||
toml = "0.4"
|
toml = "0.4"
|
||||||
|
failure = "0.1"
|
||||||
|
|
||||||
libimagerror = { version = "0.9.0", path = "../../../lib/core/libimagerror" }
|
libimagerror = { version = "0.9.0", path = "../../../lib/core/libimagerror" }
|
||||||
libimagrt = { version = "0.9.0", path = "../../../lib/core/libimagrt" }
|
libimagrt = { version = "0.9.0", path = "../../../lib/core/libimagrt" }
|
||||||
|
|
|
@ -20,10 +20,12 @@
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
use libimagstore::store::Entry;
|
use libimagstore::store::Entry;
|
||||||
|
|
||||||
use error::Result;
|
use failure::Fallible as Result;
|
||||||
use error::EditErrorKind;
|
use failure::Error;
|
||||||
use error::EditError as EE;
|
use failure::ResultExt;
|
||||||
use error::ResultExt;
|
use failure::err_msg;
|
||||||
|
|
||||||
|
use libimagerror::errors::ErrorMsg as EM;
|
||||||
|
|
||||||
pub trait Edit {
|
pub trait Edit {
|
||||||
fn edit_content(&mut self, rt: &Runtime) -> Result<()>;
|
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<()> {
|
fn edit_header_and_content(&mut self, rt: &Runtime) -> Result<()> {
|
||||||
let mut header_and_content = self.to_str()?;
|
let mut header_and_content = self.to_str()?;
|
||||||
let _ = edit_in_tmpfile(rt, &mut header_and_content)?;
|
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
|
let editor = rt
|
||||||
.editor()
|
.editor()
|
||||||
.chain_err(|| EditErrorKind::NoEditor)?
|
.context(err_msg("No editor"))?
|
||||||
.ok_or_else(|| EE::from_kind(EditErrorKind::NoEditor))?;
|
.ok_or_else(|| Error::from(err_msg("No editor")))?;
|
||||||
|
|
||||||
edit_in_tmpfile_with_command(editor, s)
|
edit_in_tmpfile_with_command(editor, s)
|
||||||
.chain_err(|| EditErrorKind::IOError)
|
.context(EM::IO)
|
||||||
.and_then(|worked| {
|
.map_err(Error::from)
|
||||||
if !worked {
|
.and_then(|worked| if !worked {
|
||||||
Err(EditErrorKind::ProcessExitFailure.into())
|
Err(Error::from(EM::ExternalProcessError))
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
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 libimagstore;
|
||||||
extern crate libimagrt;
|
extern crate libimagrt;
|
||||||
extern crate libimagutil;
|
extern crate libimagutil;
|
||||||
#[macro_use] extern crate error_chain;
|
|
||||||
extern crate toml;
|
extern crate toml;
|
||||||
|
extern crate failure;
|
||||||
|
|
||||||
pub mod edit;
|
pub mod edit;
|
||||||
pub mod error;
|
|
||||||
|
|
Loading…
Reference in a new issue