From e3911d97d945ec72c696505c8e40207f67916b9e Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 30 Oct 2018 18:40:52 +0100 Subject: [PATCH] imag-store: Move from error-chain to failure Signed-off-by: Matthias Beyer --- bin/core/imag-store/Cargo.toml | 2 +- bin/core/imag-store/src/create.rs | 18 ++++----------- bin/core/imag-store/src/error.rs | 38 ------------------------------- bin/core/imag-store/src/main.rs | 3 +-- 4 files changed, 6 insertions(+), 55 deletions(-) delete mode 100644 bin/core/imag-store/src/error.rs diff --git a/bin/core/imag-store/Cargo.toml b/bin/core/imag-store/Cargo.toml index 9bc96a41..63731f56 100644 --- a/bin/core/imag-store/Cargo.toml +++ b/bin/core/imag-store/Cargo.toml @@ -24,7 +24,7 @@ maintenance = { status = "actively-developed" } [dependencies] log = "0.4.0" toml = "0.4" -error-chain = "0.12" +failure = "0.1" libimagstore = { version = "0.9.0", path = "../../../lib/core/libimagstore", features = ["verify"] } libimagrt = { version = "0.9.0", path = "../../../lib/core/libimagrt" } diff --git a/bin/core/imag-store/src/create.rs b/bin/core/imag-store/src/create.rs index f7365b8c..6ee5ecfe 100644 --- a/bin/core/imag-store/src/create.rs +++ b/bin/core/imag-store/src/create.rs @@ -20,12 +20,13 @@ use std::path::PathBuf; use std::io::stdin; use std::fs::OpenOptions; -use std::result::Result as RResult; use std::io::Read; use std::ops::DerefMut; use clap::ArgMatches; use toml::Value; +use failure::Fallible as Result; +use failure::err_msg; use libimagrt::runtime::Runtime; use libimagstore::store::Entry; @@ -33,13 +34,8 @@ use libimagstore::storeid::StoreId; use libimagerror::trace::MapErrTrace; use libimagutil::debug_result::*; -use error::StoreError; -use error::StoreErrorKind; -use error::ResultExt; use util::build_toml_header; -type Result = RResult; - pub fn create(rt: &Runtime) { let scmd = rt.cli().subcommand_matches("create").unwrap(); debug!("Found 'create' subcommand..."); @@ -95,13 +91,9 @@ fn create_from_cli_spec(rt: &Runtime, matches: &ArgMatches, path: &StoreId) -> R fn create_from_source(rt: &Runtime, matches: &ArgMatches, path: &StoreId) -> Result<()> { let content = matches .value_of("from-raw") - .ok_or(StoreError::from_kind(StoreErrorKind::NoCommandlineCall)) - .map(string_from_raw_src); + .ok_or_else(|| err_msg("No Commandline call")) + .map(string_from_raw_src)?; - if content.is_err() { - return content.map(|_| ()); - } - let content = content.unwrap(); debug!("Content with len = {}", content.len()); Entry::from_str(path.clone(), &content[..]) @@ -118,7 +110,6 @@ fn create_from_source(rt: &Runtime, matches: &ArgMatches, path: &StoreId) -> Res r }) .map_dbg_err(|e| format!("Error storing entry: {:?}", e)) - .chain_err(|| StoreErrorKind::BackendError) } fn create_with_content_and_header(rt: &Runtime, @@ -142,7 +133,6 @@ fn create_with_content_and_header(rt: &Runtime, debug!("New header set"); } }) - .chain_err(|| StoreErrorKind::BackendError) } fn string_from_raw_src(raw_src: &str) -> String { diff --git a/bin/core/imag-store/src/error.rs b/bin/core/imag-store/src/error.rs deleted file mode 100644 index be517759..00000000 --- a/bin/core/imag-store/src/error.rs +++ /dev/null @@ -1,38 +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 { - StoreError, StoreErrorKind, ResultExt, Result; - } - - errors { - BackendError { - description("Backend Error") - display("Backend Error") - } - - NoCommandlineCall { - description("No commandline call") - display("No commandline call") - } - - } -} - diff --git a/bin/core/imag-store/src/main.rs b/bin/core/imag-store/src/main.rs index 6a907965..5328c3ac 100644 --- a/bin/core/imag-store/src/main.rs +++ b/bin/core/imag-store/src/main.rs @@ -36,7 +36,7 @@ extern crate clap; #[macro_use] extern crate log; extern crate toml; #[cfg(test)] extern crate toml_query; -#[macro_use] extern crate error_chain; +extern crate failure; #[macro_use] extern crate libimagrt; extern crate libimagstore; @@ -54,7 +54,6 @@ use libimagerror::trace::MapErrTrace; mod create; mod delete; -mod error; mod get; mod retrieve; mod ui;