imag-store: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
parent
3272dbfd74
commit
e3911d97d9
4 changed files with 6 additions and 55 deletions
|
@ -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" }
|
||||
|
|
|
@ -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<T> = RResult<T, StoreError>;
|
||||
|
||||
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 {
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue