diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2018-10-30 18:40:50 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2018-10-30 18:46:28 +0100 |
commit | cc503920d0ce54fe959b5735cab877972d6b8931 (patch) | |
tree | 051bde04d4bd65b505dfde6da0e5431574e0d35a /lib/etc | |
parent | 5627bbe4542a0f50f21e0384bfe29486cc29214a (diff) |
libimaginteraction: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'lib/etc')
-rw-r--r-- | lib/etc/libimaginteraction/Cargo.toml | 3 | ||||
-rw-r--r-- | lib/etc/libimaginteraction/src/ask.rs | 11 | ||||
-rw-r--r-- | lib/etc/libimaginteraction/src/error.rs | 83 | ||||
-rw-r--r-- | lib/etc/libimaginteraction/src/lib.rs | 3 | ||||
-rw-r--r-- | lib/etc/libimaginteraction/src/readline.rs | 28 | ||||
-rw-r--r-- | lib/etc/libimaginteraction/src/ui.rs | 17 |
6 files changed, 28 insertions, 117 deletions
diff --git a/lib/etc/libimaginteraction/Cargo.toml b/lib/etc/libimaginteraction/Cargo.toml index b4755787..b198afde 100644 --- a/lib/etc/libimaginteraction/Cargo.toml +++ b/lib/etc/libimaginteraction/Cargo.toml @@ -26,9 +26,10 @@ lazy_static = "1" log = "0.4.0" regex = "1" toml = "0.4" -error-chain = "0.12" handlebars = "1.0" serde_json = "1" +failure = "0.1" +failure_derive = "0.1" libimagstore = { version = "0.9.0", path = "../../../lib/core/libimagstore" } libimagerror = { version = "0.9.0", path = "../../../lib/core/libimagerror" } diff --git a/lib/etc/libimaginteraction/src/ask.rs b/lib/etc/libimaginteraction/src/ask.rs index e2997391..0c6c55cd 100644 --- a/lib/etc/libimaginteraction/src/ask.rs +++ b/lib/etc/libimaginteraction/src/ask.rs @@ -24,13 +24,13 @@ use std::io::BufRead; use std::io::BufReader; use std::result::Result as RResult; -use error::InteractionErrorKind; -use error::ResultExt; -use error::Result; - use regex::Regex; use ansi_term::Colour::*; use interactor::*; +use failure::Error; +use failure::ResultExt; +use failure::Fallible as Result; +use failure::err_msg; /// Ask the user for a Yes/No answer. Optionally provide a default value. If none is provided, this /// keeps loop{}ing @@ -163,7 +163,8 @@ fn ask_string_<R: BufRead>(s: &str, pub fn ask_select_from_list(list: &[&str]) -> Result<String> { pick_from_list(default_menu_cmd().as_mut(), list, "Selection: ") - .chain_err(|| InteractionErrorKind::Unknown) + .context(err_msg("Unknown interaction error")) + .map_err(Error::from) } /// 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 deleted file mode 100644 index efa84f1b..00000000 --- a/lib/etc/libimaginteraction/src/error.rs +++ /dev/null @@ -1,83 +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 { - InteractionError, InteractionErrorKind, ResultExt, Result; - } - - errors { - Unknown { - description("Unknown Error") - display("Unknown Error") - } - - CLIError { - description("Error on commandline") - display("Error on commandline") - } - - IdMissingError { - description("Commandline: ID missing") - display("Commandline: ID missing") - } - - StoreIdParsingError { - description("Error while parsing StoreId") - display("Error while parsing StoreId") - } - - IdSelectingError { - description("Error while selecting id") - display("Error while selecting id") - } - - ConfigError { - description("Configuration error") - display("Configuration error") - } - - ConfigMissingError { - description("Configuration missing") - display("Configuration missing") - } - - ConfigTypeError { - description("Config Type Error") - display("Config Type Error") - } - - NoConfigError { - description("No configuration") - display("No configuration") - } - - ReadlineHistoryFileCreationError { - description("Could not create history file for readline") - display("Could not create history file for readline") - } - - ReadlineError { - description("Readline error") - display("Readline error") - } - - } -} - diff --git a/lib/etc/libimaginteraction/src/lib.rs b/lib/etc/libimaginteraction/src/lib.rs index 00db42d7..a2dc5d52 100644 --- a/lib/etc/libimaginteraction/src/lib.rs +++ b/lib/etc/libimaginteraction/src/lib.rs @@ -43,13 +43,12 @@ extern crate clap; extern crate toml; extern crate handlebars; extern crate serde_json; -#[macro_use] extern crate error_chain; +extern crate failure; extern crate libimagstore; extern crate libimagerror; pub mod ask; -pub mod error; pub mod filter; pub mod format; pub mod ui; diff --git a/lib/etc/libimaginteraction/src/readline.rs b/lib/etc/libimaginteraction/src/readline.rs index 6aaede95..1b29826f 100644 --- a/lib/etc/libimaginteraction/src/readline.rs +++ b/lib/etc/libimaginteraction/src/readline.rs @@ -17,10 +17,8 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use error::InteractionError as IE; -use error::InteractionErrorKind as IEK; -use error::ResultExt; +use failure::ResultExt; use toml::Value; use rustyline::{Config, Editor}; @@ -46,32 +44,32 @@ impl Readline { .as_str() .map(PathBuf::from) .ok_or(IE::from_kind(IEK::ConfigTypeError)) - .chain_err(|| IEK::ConfigError) - .chain_err(|| IEK::ReadlineError)?; + .context(IEK::ConfigError) + .context(IEK::ReadlineError)?; let histsize = histsize .as_int() .ok_or(IE::from_kind(IEK::ConfigTypeError)) - .chain_err(|| IEK::ConfigError) - .chain_err(|| IEK::ReadlineError)?; + .context(IEK::ConfigError) + .context(IEK::ReadlineError)?; let histigndups = histigndups .as_bool() .ok_or(IE::from_kind(IEK::ConfigTypeError)) - .chain_err(|| IEK::ConfigError) - .chain_err(|| IEK::ReadlineError)?; + .context(IEK::ConfigError) + .context(IEK::ReadlineError)?; let histignspace = histignspace .as_bool() .ok_or(IE::from_kind(IEK::ConfigTypeError)) - .chain_err(|| IEK::ConfigError) - .chain_err(|| IEK::ReadlineError)?; + .context(IEK::ConfigError) + .context(IEK::ReadlineError)?; let prompt = prompt .as_str() .ok_or(IE::from_kind(IEK::ConfigTypeError)) - .chain_err(|| IEK::ConfigError) - .chain_err(|| IEK::ReadlineError)?; + .context(IEK::ConfigError) + .context(IEK::ReadlineError)?; let config = Config::builder(). .max_history_size(histsize) @@ -83,10 +81,10 @@ impl Readline { if !histfile.exists() { let _ = File::create(histfile.clone()) - .chain_err(|| IEK::ReadlineHistoryFileCreationError)?; + .context(IEK::ReadlineHistoryFileCreationError)?; } - let _ = editor.load_history(&histfile).chain_err(|| ReadlineError)?; + let _ = editor.load_history(&histfile).context(ReadlineError)?; Ok(Readline { editor: editor, diff --git a/lib/etc/libimaginteraction/src/ui.rs b/lib/etc/libimaginteraction/src/ui.rs index 916dbebc..57bcb409 100644 --- a/lib/etc/libimaginteraction/src/ui.rs +++ b/lib/etc/libimaginteraction/src/ui.rs @@ -23,10 +23,8 @@ use clap::{Arg, ArgMatches}; use libimagstore::storeid::StoreId; -use error::InteractionError as IE; -use error::Result; -use error::InteractionErrorKind as IEK; -use error::ResultExt; +use failure::err_msg; +use failure::Fallible as Result; pub fn id_argument<'a, 'b>() -> Arg<'a, 'b> { Arg::with_name(id_argument_name()) @@ -52,14 +50,12 @@ pub fn id_argument_long() -> &'static str { pub fn get_id(matches: &ArgMatches) -> Result<Vec<StoreId>> { matches .values_of(id_argument_name()) - .ok_or(IE::from_kind(IEK::IdMissingError)) - .chain_err(|| IEK::CLIError) + .ok_or(err_msg("CLI error")) .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 = elem.chain_err(|| IEK::StoreIdParsingError)?; + let elem = StoreId::new_baseless(PathBuf::from(String::from(elem)))?; v.push(elem); Ok(v) }) @@ -71,11 +67,10 @@ pub fn get_or_select_id(matches: &ArgMatches, store_path: &PathBuf) -> Result<Ve use interactor::{pick_file, default_menu_cmd}; get_id(matches) - .chain_err(|| IEK::IdSelectingError) .or_else(|_| { let path = store_path.clone(); - let p = pick_file(default_menu_cmd, path).chain_err(|| IEK::IdSelectingError)?; - let id = StoreId::new_baseless(p).chain_err(|| IEK::StoreIdParsingError)?; + let p = pick_file(default_menu_cmd, path)?; + let id = StoreId::new_baseless(p)?; Ok(vec![id]) }) } |