summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2017-09-03 15:10:11 +0200
committerMatthias Beyer <mail@beyermatthias.de>2017-09-03 21:33:54 +0200
commit9aa5d7439d864aeeb9667f08f3d83eb60605cffa (patch)
tree7eb5346e9e13579a418a770a1cd6e4b1bf6f3ff8
parent4b4b0b0804cabdd81d0a8341aa520bc4d5e2fa0f (diff)
libimagentrylist: Rewrite error handling
-rw-r--r--lib/entry/libimagentrylist/src/cli.rs5
-rw-r--r--lib/entry/libimagentrylist/src/error.rs10
-rw-r--r--lib/entry/libimagentrylist/src/lib.rs2
-rw-r--r--lib/entry/libimagentrylist/src/listers/core.rs4
-rw-r--r--lib/entry/libimagentrylist/src/listers/line.rs4
-rw-r--r--lib/entry/libimagentrylist/src/listers/path.rs19
-rw-r--r--lib/entry/libimagentrylist/src/listers/table.rs4
7 files changed, 19 insertions, 29 deletions
diff --git a/lib/entry/libimagentrylist/src/cli.rs b/lib/entry/libimagentrylist/src/cli.rs
index b52a92fd..4b94d3bb 100644
--- a/lib/entry/libimagentrylist/src/cli.rs
+++ b/lib/entry/libimagentrylist/src/cli.rs
@@ -20,12 +20,13 @@
use clap::{Arg, ArgMatches, App, SubCommand};
use libimagstore::store::FileLockEntry;
+use libimagerror::into::IntoError;
use result::Result;
use listers::line::LineLister;
use listers::path::PathLister;
use lister::Lister;
-use error::{ListError, ListErrorKind};
+use error::ListErrorKind;
pub fn build_list_cli_component<'a, 'b>() -> App<'a, 'b> {
SubCommand::with_name(list_subcommand_name())
@@ -96,6 +97,6 @@ pub fn list_entries_with_lister<'a, I>(m: &ArgMatches, entries: I) -> Result<()>
Ok(())
} else {
- Err(ListError::new(ListErrorKind::CLIError, None))
+ Err(ListErrorKind::CLIError.into_error())
}
}
diff --git a/lib/entry/libimagentrylist/src/error.rs b/lib/entry/libimagentrylist/src/error.rs
index fd5aea59..f45ad46d 100644
--- a/lib/entry/libimagentrylist/src/error.rs
+++ b/lib/entry/libimagentrylist/src/error.rs
@@ -17,6 +17,10 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
+use std::error::Error;
+
+use libimagerror::into::IntoError;
+
error_chain! {
types {
ListError, ListErrorKind, ResultExt, Result;
@@ -51,10 +55,6 @@ error_chain! {
}
}
-pub use self::error::ListError;
-pub use self::error::ListErrorKind;
-pub use self::error::MapErrInto;
-
impl IntoError for ListErrorKind {
type Target = ListError;
@@ -62,7 +62,7 @@ impl IntoError for ListErrorKind {
ListError::from_kind(self)
}
- fn into_error_with_cause(self, cause: Box<Error>) -> Self::Target {
+ fn into_error_with_cause(self, _: Box<Error>) -> Self::Target {
ListError::from_kind(self)
}
}
diff --git a/lib/entry/libimagentrylist/src/lib.rs b/lib/entry/libimagentrylist/src/lib.rs
index de83b60b..7d779d73 100644
--- a/lib/entry/libimagentrylist/src/lib.rs
+++ b/lib/entry/libimagentrylist/src/lib.rs
@@ -42,7 +42,7 @@ extern crate prettytable;
extern crate libimagstore;
extern crate libimagutil;
-#[macro_use] extern crate libimagerror;
+extern crate libimagerror;
pub mod cli;
pub mod error;
diff --git a/lib/entry/libimagentrylist/src/listers/core.rs b/lib/entry/libimagentrylist/src/listers/core.rs
index 733ba719..74a99f47 100644
--- a/lib/entry/libimagentrylist/src/listers/core.rs
+++ b/lib/entry/libimagentrylist/src/listers/core.rs
@@ -22,6 +22,7 @@ use std::io::Write;
use lister::Lister;
use result::Result;
+use error::ResultExt;
use libimagstore::store::FileLockEntry;
use libimagstore::store::Entry;
@@ -43,7 +44,6 @@ impl<T: Fn(&Entry) -> String> CoreLister<T> {
impl<T: Fn(&Entry) -> String> Lister for CoreLister<T> {
fn list<'b, I: Iterator<Item = FileLockEntry<'b>>>(&self, entries: I) -> Result<()> {
- use error::ListError as LE;
use error::ListErrorKind as LEK;
debug!("Called list()");
@@ -53,7 +53,7 @@ impl<T: Fn(&Entry) -> String> Lister for CoreLister<T> {
let r = accu.and_then(|_| {
debug!("Listing Entry: {:?}", entry);
write!(stdout(), "{:?}\n", (self.lister)(&entry))
- .map_err(|e| LE::new(LEK::FormatError, Some(Box::new(e))))
+ .chain_err(|| LEK::FormatError)
});
(r, i + 1)
});
diff --git a/lib/entry/libimagentrylist/src/listers/line.rs b/lib/entry/libimagentrylist/src/listers/line.rs
index 8c439934..d61b8da3 100644
--- a/lib/entry/libimagentrylist/src/listers/line.rs
+++ b/lib/entry/libimagentrylist/src/listers/line.rs
@@ -22,6 +22,7 @@ use std::io::Write;
use lister::Lister;
use result::Result;
+use error::ResultExt;
use libimagstore::store::FileLockEntry;
use libimagutil::iter::FoldResult;
@@ -43,12 +44,11 @@ impl<'a> LineLister<'a> {
impl<'a> Lister for LineLister<'a> {
fn list<'b, I: Iterator<Item = FileLockEntry<'b>>>(&self, entries: I) -> Result<()> {
- use error::ListError as LE;
use error::ListErrorKind as LEK;
entries.fold_result(|entry| {
let s = entry.get_location().to_str().unwrap_or(String::from(self.unknown_output));
- write!(stdout(), "{:?}\n", s).map_err(|e| LE::new(LEK::FormatError, Some(Box::new(e))))
+ write!(stdout(), "{:?}\n", s).chain_err(| | LEK::FormatError)
})
}
diff --git a/lib/entry/libimagentrylist/src/listers/path.rs b/lib/entry/libimagentrylist/src/listers/path.rs
index 15a2df5b..55a9afb0 100644
--- a/lib/entry/libimagentrylist/src/listers/path.rs
+++ b/lib/entry/libimagentrylist/src/listers/path.rs
@@ -22,7 +22,7 @@ use std::io::Write;
use lister::Lister;
use result::Result;
-use error::MapErrInto;
+use error::ResultExt;
use libimagstore::store::FileLockEntry;
use libimagutil::iter::FoldResult;
@@ -44,30 +44,19 @@ impl PathLister {
impl Lister for PathLister {
fn list<'a, I: Iterator<Item = FileLockEntry<'a>>>(&self, entries: I) -> Result<()> {
- use error::ListError as LE;
use error::ListErrorKind as LEK;
entries.fold_result(|entry| {
Ok(entry.get_location().clone())
- .and_then(|pb| pb.into_pathbuf().map_err_into(LEK::FormatError))
+ .and_then(|pb| pb.into_pathbuf().chain_err(|| LEK::FormatError))
.and_then(|pb| {
if self.absolute {
- pb.canonicalize().map_err(|e| LE::new(LEK::FormatError, Some(Box::new(e))))
+ pb.canonicalize().chain_err(|| LEK::FormatError)
} else {
Ok(pb.into())
}
})
- .and_then(|pb| {
- write!(stdout(), "{:?}\n", pb)
- .map_err(|e| LE::new(LEK::FormatError, Some(Box::new(e))))
- })
- .map_err(|e| {
- if e.err_type() == LEK::FormatError {
- e
- } else {
- LE::new(LEK::FormatError, Some(Box::new(e)))
- }
- })
+ .and_then(|pb| write!(stdout(), "{:?}\n", pb).chain_err(|| LEK::FormatError))
})
}
diff --git a/lib/entry/libimagentrylist/src/listers/table.rs b/lib/entry/libimagentrylist/src/listers/table.rs
index e9358ce3..040b27ad 100644
--- a/lib/entry/libimagentrylist/src/listers/table.rs
+++ b/lib/entry/libimagentrylist/src/listers/table.rs
@@ -21,7 +21,7 @@ use std::io::stdout;
use lister::Lister;
use result::Result;
-use error::MapErrInto;
+use error::ResultExt;
use libimagstore::store::FileLockEntry;
use libimagerror::into::IntoError;
@@ -103,7 +103,7 @@ impl<F: Fn(&FileLockEntry) -> Vec<String>> Lister for TableLister<F> {
})
.and_then(|tbl| {
let mut io = stdout();
- tbl.print(&mut io).map_err_into(LEK::IOError)
+ tbl.print(&mut io).chain_err(|| LEK::IOError)
})
}