diff --git a/lib/etc/libimaginteraction/src/ask.rs b/lib/etc/libimaginteraction/src/ask.rs index 2a393d0e..475a2f0d 100644 --- a/lib/etc/libimaginteraction/src/ask.rs +++ b/lib/etc/libimaginteraction/src/ask.rs @@ -24,8 +24,8 @@ use std::io::BufRead; use std::io::BufReader; use std::result::Result as RResult; -use error::InteractionError; use error::InteractionErrorKind; +use error::ResultExt; use result::Result; use regex::Regex; @@ -163,7 +163,7 @@ fn ask_string_(s: &str, pub fn ask_select_from_list(list: &[&str]) -> Result { pick_from_list(default_menu_cmd().as_mut(), list, "Selection: ") - .map_err(|e| InteractionError::new(InteractionErrorKind::Unknown, Some(Box::new(e)))) + .chain_err(|| InteractionErrorKind::Unknown) } /// Helper function to print a imag question string. The `question` argument may not contain a diff --git a/lib/etc/libimaginteraction/src/error.rs b/lib/etc/libimaginteraction/src/error.rs index 271bf832..e5daf160 100644 --- a/lib/etc/libimaginteraction/src/error.rs +++ b/lib/etc/libimaginteraction/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 { InteractionError, InteractionErrorKind, ResultExt, Result; @@ -81,10 +85,6 @@ error_chain! { } } -pub use self::error::InteractionError; -pub use self::error::InteractionErrorKind; -pub use self::error::MapErrInto; - impl IntoError for InteractionErrorKind { type Target = InteractionError; @@ -92,7 +92,7 @@ impl IntoError for InteractionErrorKind { InteractionError::from_kind(self) } - fn into_error_with_cause(self, cause: Box) -> Self::Target { + fn into_error_with_cause(self, _: Box) -> Self::Target { InteractionError::from_kind(self) } } diff --git a/lib/etc/libimaginteraction/src/lib.rs b/lib/etc/libimaginteraction/src/lib.rs index ae78b8c8..36f9a04d 100644 --- a/lib/etc/libimaginteraction/src/lib.rs +++ b/lib/etc/libimaginteraction/src/lib.rs @@ -44,7 +44,7 @@ extern crate toml; #[macro_use] extern crate error_chain; extern crate libimagstore; -#[macro_use] extern crate libimagerror; +extern crate libimagerror; pub mod ask; pub mod error; diff --git a/lib/etc/libimaginteraction/src/ui.rs b/lib/etc/libimaginteraction/src/ui.rs index 49c4619d..0a5335b9 100644 --- a/lib/etc/libimaginteraction/src/ui.rs +++ b/lib/etc/libimaginteraction/src/ui.rs @@ -25,8 +25,8 @@ use libimagstore::storeid::StoreId; use libimagerror::into::IntoError; use result::Result; -use error::MapErrInto; use error::InteractionErrorKind as IEK; +use error::ResultExt; pub fn id_argument<'a, 'b>() -> Arg<'a, 'b> { Arg::with_name(id_argument_name()) @@ -53,13 +53,13 @@ pub fn get_id(matches: &ArgMatches) -> Result> { matches .values_of(id_argument_name()) .ok_or(IEK::IdMissingError.into_error()) - .map_err_into(IEK::CLIError) + .chain_err(|| IEK::CLIError) .and_then(|vals| { vals.into_iter() .fold(Ok(vec![]), |acc, elem| { acc.and_then(|mut v| { let elem = StoreId::new_baseless(PathBuf::from(String::from(elem))); - let elem = try!(elem.map_err_into(IEK::StoreIdParsingError)); + let elem = try!(elem.chain_err(|| IEK::StoreIdParsingError)); v.push(elem); Ok(v) }) @@ -70,12 +70,12 @@ pub fn get_id(matches: &ArgMatches) -> Result> { pub fn get_or_select_id(matches: &ArgMatches, store_path: &PathBuf) -> Result> { use interactor::{pick_file, default_menu_cmd}; - match get_id(matches).map_err_into(IEK::IdSelectingError) { + match get_id(matches).chain_err(|| IEK::IdSelectingError) { Ok(v) => Ok(v), Err(_) => { let path = store_path.clone(); - let p = try!(pick_file(default_menu_cmd, path).map_err_into(IEK::IdSelectingError)); - let id = try!(StoreId::new_baseless(p).map_err_into(IEK::StoreIdParsingError)); + let p = try!(pick_file(default_menu_cmd, path).chain_err(|| IEK::IdSelectingError)); + let id = try!(StoreId::new_baseless(p).chain_err(|| IEK::StoreIdParsingError)); Ok(vec![id]) }, }