From ebe2a9a110b97ee68beb64276bba4327d20d3fea Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 30 Oct 2018 18:40:52 +0100 Subject: [PATCH] libimagentryview: Move from error-chain to failure Signed-off-by: Matthias Beyer --- lib/entry/libimagentryview/Cargo.toml | 5 +- .../libimagentryview/src/builtin/editor.rs | 11 ++-- lib/entry/libimagentryview/src/builtin/md.rs | 6 +- .../libimagentryview/src/builtin/plain.rs | 2 +- .../libimagentryview/src/builtin/stdout.rs | 2 +- lib/entry/libimagentryview/src/error.rs | 62 ------------------- lib/entry/libimagentryview/src/lib.rs | 6 +- lib/entry/libimagentryview/src/viewer.rs | 6 +- 8 files changed, 17 insertions(+), 83 deletions(-) delete mode 100644 lib/entry/libimagentryview/src/error.rs diff --git a/lib/entry/libimagentryview/Cargo.toml b/lib/entry/libimagentryview/Cargo.toml index 705e4804..635dfc80 100644 --- a/lib/entry/libimagentryview/Cargo.toml +++ b/lib/entry/libimagentryview/Cargo.toml @@ -22,7 +22,7 @@ maintenance = { status = "actively-developed" } [dependencies] log = "0.4.0" toml = "0.4" -error-chain = "0.12" +failure = "0.1" textwrap = "0.10" libimagrt = { version = "0.9.0", path = "../../../lib/core/libimagrt" } @@ -31,7 +31,6 @@ libimagerror = { version = "0.9.0", path = "../../../lib/core/libimagerror" libimagentryedit = { version = "0.9.0", path = "../../../lib/entry/libimagentryedit" } mdcat = { version = "0.8", optional = true } -failure = { version = "0.1", optional = true } [dependencies.pulldown-cmark] version = "^0.1" @@ -47,5 +46,5 @@ features = ["parsing", "assets", "dump-load"] [features] default = [ "markdownviewer" ] -markdownviewer = ["mdcat", "failure", "pulldown-cmark", "syntect"] +markdownviewer = ["mdcat", "pulldown-cmark", "syntect"] diff --git a/lib/entry/libimagentryview/src/builtin/editor.rs b/lib/entry/libimagentryview/src/builtin/editor.rs index c5cd7394..29d2d68a 100644 --- a/lib/entry/libimagentryview/src/builtin/editor.rs +++ b/lib/entry/libimagentryview/src/builtin/editor.rs @@ -24,9 +24,10 @@ use libimagrt::runtime::Runtime; use libimagentryedit::edit::edit_in_tmpfile; use viewer::Viewer; -use error::Result; -use error::ResultExt; -use error::ViewErrorKind as VEK; +use failure::Fallible as Result; +use failure::ResultExt; +use failure::Error; +use failure::err_msg; pub struct EditorView<'a>(&'a Runtime<'a>); @@ -41,7 +42,9 @@ impl<'a> Viewer for EditorView<'a> { where W: Write { let mut entry = e.to_str()?.clone().to_string(); - edit_in_tmpfile(self.0, &mut entry).chain_err(|| VEK::ViewError) + edit_in_tmpfile(self.0, &mut entry) + .context(err_msg("Error while viewing")) + .map_err(Error::from) } } diff --git a/lib/entry/libimagentryview/src/builtin/md.rs b/lib/entry/libimagentryview/src/builtin/md.rs index 630719e3..83d247e9 100644 --- a/lib/entry/libimagentryview/src/builtin/md.rs +++ b/lib/entry/libimagentryview/src/builtin/md.rs @@ -28,7 +28,8 @@ use syntect::parsing::SyntaxSet; use mdcat; use viewer::Viewer; -use error::Result; +use failure::Fallible as Result; +use failure::Error; pub struct MarkdownViewer<'a> { rt: &'a Runtime<'a>, @@ -66,8 +67,7 @@ impl<'a> Viewer for MarkdownViewer<'a> { base_dir, self.resource_access.clone(), syntax_set) - .map_err(|e| e.compat()) - .map_err(::error::ViewError::from) + .map_err(Error::from) } } diff --git a/lib/entry/libimagentryview/src/builtin/plain.rs b/lib/entry/libimagentryview/src/builtin/plain.rs index b276ed93..cb30a3db 100644 --- a/lib/entry/libimagentryview/src/builtin/plain.rs +++ b/lib/entry/libimagentryview/src/builtin/plain.rs @@ -22,7 +22,7 @@ use std::io::Write; use libimagstore::store::Entry; use viewer::Viewer; -use error::Result; +use failure::Fallible as Result; pub struct PlainViewer { show_header: bool diff --git a/lib/entry/libimagentryview/src/builtin/stdout.rs b/lib/entry/libimagentryview/src/builtin/stdout.rs index f74f6b14..5f5b93df 100644 --- a/lib/entry/libimagentryview/src/builtin/stdout.rs +++ b/lib/entry/libimagentryview/src/builtin/stdout.rs @@ -24,7 +24,7 @@ use libimagstore::store::Entry; use toml::ser::to_string; use viewer::Viewer; -use error::Result; +use failure::Fallible as Result; pub struct StdoutViewer { view_header: bool, diff --git a/lib/entry/libimagentryview/src/error.rs b/lib/entry/libimagentryview/src/error.rs deleted file mode 100644 index c549fe88..00000000 --- a/lib/entry/libimagentryview/src/error.rs +++ /dev/null @@ -1,62 +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 { - ViewError, ViewErrorKind, ResultExt, Result; - } - - foreign_links { - Failure(::failure::Compat<::failure::Error>) #[cfg(feature = "markdownviewer")]; - IO(::std::io::Error); - } - - links { - StoreError(::libimagstore::error::StoreError, ::libimagstore::error::StoreErrorKind); - } - - errors { - Unknown { - description("Unknown view error") - display("Unknown view error") - } - - GlobError { - description("Error while glob()ing") - display("Error while glob()ing") - } - - PatternError { - description("Error in glob() pattern") - display("Error in glob() pattern") - } - - PatternBuildingError { - description("Could not build glob() pattern") - display("Could not build glob() pattern") - } - - ViewError { - description("Failed to start viewer") - display("Failed to start viewer") - } - - } -} - diff --git a/lib/entry/libimagentryview/src/lib.rs b/lib/entry/libimagentryview/src/lib.rs index 52f30a0f..19d40baa 100644 --- a/lib/entry/libimagentryview/src/lib.rs +++ b/lib/entry/libimagentryview/src/lib.rs @@ -36,15 +36,12 @@ )] extern crate toml; -#[macro_use] extern crate error_chain; extern crate textwrap; +extern crate failure; #[cfg(feature = "markdownviewer")] extern crate mdcat; -#[cfg(feature = "markdownviewer")] -extern crate failure; - #[cfg(feature = "markdownviewer")] extern crate pulldown_cmark; @@ -56,7 +53,6 @@ extern crate libimagrt; extern crate libimagerror; extern crate libimagentryedit; -pub mod error; pub mod builtin; pub mod viewer; diff --git a/lib/entry/libimagentryview/src/viewer.rs b/lib/entry/libimagentryview/src/viewer.rs index dc0194cd..7dc4c6c5 100644 --- a/lib/entry/libimagentryview/src/viewer.rs +++ b/lib/entry/libimagentryview/src/viewer.rs @@ -22,7 +22,7 @@ use std::ops::Deref; use libimagstore::store::Entry; -use error::Result; +use failure::Fallible as Result; pub trait Viewer { @@ -35,9 +35,7 @@ pub trait Viewer { W: Write { for entry in entries { - if let Err(e) = self.view_entry(entry.deref(), sink) { - return Err(e); - } + let _ = self.view_entry(entry.deref(), sink)?; } Ok(()) }