libimagentryview: Move from error-chain to failure

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
Matthias Beyer 2018-10-30 18:40:52 +01:00
parent 9b48dc27cd
commit ebe2a9a110
8 changed files with 17 additions and 83 deletions

View file

@ -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"]

View file

@ -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)
}
}

View file

@ -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)
}
}

View file

@ -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

View file

@ -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,

View file

@ -1,62 +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 {
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")
}
}
}

View file

@ -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;

View file

@ -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(())
}