libimagentryedit: Rewrite error handling

This commit is contained in:
Matthias Beyer 2017-09-03 15:03:52 +02:00
parent ca0dd5906d
commit 4b4b0b0804
3 changed files with 8 additions and 8 deletions

View file

@ -23,7 +23,7 @@ use libimagstore::store::Entry;
use result::Result; use result::Result;
use error::EditErrorKind; use error::EditErrorKind;
use error::MapErrInto; use error::ResultExt;
pub trait Edit { pub trait Edit {
fn edit_content(&mut self, rt: &Runtime) -> Result<()>; fn edit_content(&mut self, rt: &Runtime) -> Result<()>;
@ -53,7 +53,7 @@ pub fn edit_in_tmpfile(rt: &Runtime, s: &mut String) -> Result<()> {
.ok_or(EditErrorKind::NoEditor.into_error()) .ok_or(EditErrorKind::NoEditor.into_error())
.and_then(|editor| { .and_then(|editor| {
edit_in_tmpfile_with_command(editor, s) edit_in_tmpfile_with_command(editor, s)
.map_err_into(EditErrorKind::IOError) .chain_err(|| EditErrorKind::IOError)
.and_then(|worked| { .and_then(|worked| {
if !worked { if !worked {
Err(EditErrorKind::ProcessExitFailure.into()) Err(EditErrorKind::ProcessExitFailure.into())

View file

@ -17,6 +17,10 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
// //
use std::error::Error;
use libimagerror::into::IntoError;
error_chain! { error_chain! {
types { types {
EditError, EditErrorKind, ResultExt, Result; EditError, EditErrorKind, ResultExt, Result;
@ -46,10 +50,6 @@ error_chain! {
} }
} }
pub use self::error::EditError;
pub use self::error::EditErrorKind;
pub use self::error::MapErrInto;
impl IntoError for EditErrorKind { impl IntoError for EditErrorKind {
type Target = EditError; type Target = EditError;
@ -57,7 +57,7 @@ impl IntoError for EditErrorKind {
EditError::from_kind(self) EditError::from_kind(self)
} }
fn into_error_with_cause(self, cause: Box<Error>) -> Self::Target { fn into_error_with_cause(self, _: Box<Error>) -> Self::Target {
EditError::from_kind(self) EditError::from_kind(self)
} }
} }

View file

@ -35,7 +35,7 @@
while_true, while_true,
)] )]
#[macro_use] extern crate libimagerror; extern crate libimagerror;
extern crate libimagstore; extern crate libimagstore;
extern crate libimagrt; extern crate libimagrt;
extern crate libimagutil; extern crate libimagutil;