From daca530dd57065560bb234516ee563047b790474 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 6 Sep 2016 11:27:42 +0200 Subject: [PATCH] imag-store: Use Err/Ok Result map utils to refactor code --- imag-store/src/delete.rs | 13 +++++-------- imag-store/src/retrieve.rs | 13 ++++++------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/imag-store/src/delete.rs b/imag-store/src/delete.rs index 70594e2a..885a089c 100644 --- a/imag-store/src/delete.rs +++ b/imag-store/src/delete.rs @@ -1,13 +1,12 @@ use std::path::PathBuf; use libimagrt::runtime::Runtime; -use libimagerror::trace::trace_error_exit; +use libimagerror::trace::MapErrTrace; use libimagstore::storeid::StoreId; use libimagutil::warn_exit::warn_exit; +use libimagutil::warn_result::*; pub fn delete(rt: &Runtime) { - use std::process::exit; - rt.cli() .subcommand_matches("delete") .map(|sub| { @@ -15,15 +14,13 @@ pub fn delete(rt: &Runtime) { .map(|id| { let path = PathBuf::from(id); let path = try!(StoreId::new(Some(rt.store().path().clone()), path) - .map_err(|e| trace_error_exit(&e, 1))); + .map_err_trace_exit(1)); debug!("Deleting file at {:?}", id); rt.store() .delete(path) - .map_err(|e| { - warn!("Error: {:?}", e); - exit(1); - }) + .map_warn_err(|e| format!("Error: {:?}", e)) + .map_err_trace_exit(1) }) .or_else(|| warn_exit("No ID passed. Will exit now", 1)) }) diff --git a/imag-store/src/retrieve.rs b/imag-store/src/retrieve.rs index 39b66741..41f8e936 100644 --- a/imag-store/src/retrieve.rs +++ b/imag-store/src/retrieve.rs @@ -6,7 +6,8 @@ use toml::Value; use libimagstore::store::FileLockEntry; use libimagstore::storeid::StoreId; use libimagrt::runtime::Runtime; -use libimagerror::trace::{trace_error, trace_error_exit}; +use libimagerror::trace::MapErrTrace; +use libimagutil::debug_result::*; pub fn retrieve(rt: &Runtime) { rt.cli() @@ -16,18 +17,16 @@ pub fn retrieve(rt: &Runtime) { .map(|id| { let path = PathBuf::from(id); let path = try!(StoreId::new(Some(rt.store().path().clone()), path) - .map_err(|e| trace_error_exit(&e, 1))); + .map_err_trace_exit(1)); debug!("path = {:?}", path); rt.store() // "id" must be present, enforced via clap spec .retrieve(path) .map(|e| print_entry(rt, scmd, e)) - .map_err(|e| { - debug!("No entry."); - debug!("{}:", e); - trace_error(&e); - }) + .map_dbg_str("No entry") + .map_dbg(|e| format!("{:?}", e)) + .map_err_trace() }) }); }