imag-store: 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 3272dbfd74
commit e3911d97d9
4 changed files with 6 additions and 55 deletions

View file

@ -24,7 +24,7 @@ maintenance = { status = "actively-developed" }
[dependencies] [dependencies]
log = "0.4.0" log = "0.4.0"
toml = "0.4" toml = "0.4"
error-chain = "0.12" failure = "0.1"
libimagstore = { version = "0.9.0", path = "../../../lib/core/libimagstore", features = ["verify"] } libimagstore = { version = "0.9.0", path = "../../../lib/core/libimagstore", features = ["verify"] }
libimagrt = { version = "0.9.0", path = "../../../lib/core/libimagrt" } libimagrt = { version = "0.9.0", path = "../../../lib/core/libimagrt" }

View file

@ -20,12 +20,13 @@
use std::path::PathBuf; use std::path::PathBuf;
use std::io::stdin; use std::io::stdin;
use std::fs::OpenOptions; use std::fs::OpenOptions;
use std::result::Result as RResult;
use std::io::Read; use std::io::Read;
use std::ops::DerefMut; use std::ops::DerefMut;
use clap::ArgMatches; use clap::ArgMatches;
use toml::Value; use toml::Value;
use failure::Fallible as Result;
use failure::err_msg;
use libimagrt::runtime::Runtime; use libimagrt::runtime::Runtime;
use libimagstore::store::Entry; use libimagstore::store::Entry;
@ -33,13 +34,8 @@ use libimagstore::storeid::StoreId;
use libimagerror::trace::MapErrTrace; use libimagerror::trace::MapErrTrace;
use libimagutil::debug_result::*; use libimagutil::debug_result::*;
use error::StoreError;
use error::StoreErrorKind;
use error::ResultExt;
use util::build_toml_header; use util::build_toml_header;
type Result<T> = RResult<T, StoreError>;
pub fn create(rt: &Runtime) { pub fn create(rt: &Runtime) {
let scmd = rt.cli().subcommand_matches("create").unwrap(); let scmd = rt.cli().subcommand_matches("create").unwrap();
debug!("Found 'create' subcommand..."); 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<()> { fn create_from_source(rt: &Runtime, matches: &ArgMatches, path: &StoreId) -> Result<()> {
let content = matches let content = matches
.value_of("from-raw") .value_of("from-raw")
.ok_or(StoreError::from_kind(StoreErrorKind::NoCommandlineCall)) .ok_or_else(|| err_msg("No Commandline call"))
.map(string_from_raw_src); .map(string_from_raw_src)?;
if content.is_err() {
return content.map(|_| ());
}
let content = content.unwrap();
debug!("Content with len = {}", content.len()); debug!("Content with len = {}", content.len());
Entry::from_str(path.clone(), &content[..]) Entry::from_str(path.clone(), &content[..])
@ -118,7 +110,6 @@ fn create_from_source(rt: &Runtime, matches: &ArgMatches, path: &StoreId) -> Res
r r
}) })
.map_dbg_err(|e| format!("Error storing entry: {:?}", e)) .map_dbg_err(|e| format!("Error storing entry: {:?}", e))
.chain_err(|| StoreErrorKind::BackendError)
} }
fn create_with_content_and_header(rt: &Runtime, fn create_with_content_and_header(rt: &Runtime,
@ -142,7 +133,6 @@ fn create_with_content_and_header(rt: &Runtime,
debug!("New header set"); debug!("New header set");
} }
}) })
.chain_err(|| StoreErrorKind::BackendError)
} }
fn string_from_raw_src(raw_src: &str) -> String { fn string_from_raw_src(raw_src: &str) -> String {

View file

@ -1,38 +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 {
StoreError, StoreErrorKind, ResultExt, Result;
}
errors {
BackendError {
description("Backend Error")
display("Backend Error")
}
NoCommandlineCall {
description("No commandline call")
display("No commandline call")
}
}
}

View file

@ -36,7 +36,7 @@ extern crate clap;
#[macro_use] extern crate log; #[macro_use] extern crate log;
extern crate toml; extern crate toml;
#[cfg(test)] extern crate toml_query; #[cfg(test)] extern crate toml_query;
#[macro_use] extern crate error_chain; extern crate failure;
#[macro_use] extern crate libimagrt; #[macro_use] extern crate libimagrt;
extern crate libimagstore; extern crate libimagstore;
@ -54,7 +54,6 @@ use libimagerror::trace::MapErrTrace;
mod create; mod create;
mod delete; mod delete;
mod error;
mod get; mod get;
mod retrieve; mod retrieve;
mod ui; mod ui;