From 3845399fb8221155adcee6994352c21d1ce696f6 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 11 Feb 2018 19:37:52 +0100 Subject: [PATCH] Simplify implementation for new libimagerror interface --- bin/core/imag-store/src/create.rs | 9 +++------ bin/core/imag-store/src/delete.rs | 3 +-- bin/core/imag-store/src/dump.rs | 26 +++++++------------------- bin/core/imag-store/src/get.rs | 11 +++++------ bin/core/imag-store/src/update.rs | 4 ++-- 5 files changed, 18 insertions(+), 35 deletions(-) diff --git a/bin/core/imag-store/src/create.rs b/bin/core/imag-store/src/create.rs index 2aed5d80..492655f2 100644 --- a/bin/core/imag-store/src/create.rs +++ b/bin/core/imag-store/src/create.rs @@ -30,7 +30,7 @@ use toml::Value; use libimagrt::runtime::Runtime; use libimagstore::store::Entry; use libimagstore::storeid::StoreId; -use libimagerror::trace::trace_error_exit; +use libimagerror::trace::MapErrTrace; use libimagutil::debug_result::*; use error::StoreError; @@ -48,7 +48,7 @@ pub fn create(rt: &Runtime) { let path = scmd.value_of("path").unwrap(); let path = PathBuf::from(path); let store = Some(rt.store().path().clone()); - let path = StoreId::new(store, path).unwrap_or_else(|e| trace_error_exit(&e, 1)); + let path = StoreId::new(store, path).map_err_trace_exit_unwrap(1); debug!("path = {:?}", path); @@ -65,10 +65,7 @@ pub fn create(rt: &Runtime) { create_with_content_and_header(rt, &path, String::new(), Entry::default_header()) } - .unwrap_or_else(|e| { - error!("Error building Entry"); - trace_error_exit(&e, 1); - }) + .map_err_trace_exit_unwrap(1); } fn create_from_cli_spec(rt: &Runtime, matches: &ArgMatches, path: &StoreId) -> Result<()> { diff --git a/bin/core/imag-store/src/delete.rs b/bin/core/imag-store/src/delete.rs index 9e1254de..d90fd032 100644 --- a/bin/core/imag-store/src/delete.rs +++ b/bin/core/imag-store/src/delete.rs @@ -21,7 +21,6 @@ use std::path::PathBuf; use libimagrt::runtime::Runtime; use libimagerror::trace::MapErrTrace; -use libimagerror::trace::trace_error_exit; use libimagstore::storeid::StoreId; use libimagutil::warn_result::*; @@ -30,7 +29,7 @@ pub fn delete(rt: &Runtime) { let id = scmd.value_of("id").unwrap(); // safe by clap let path = PathBuf::from(id); let store = Some(rt.store().path().clone()); - let path = StoreId::new(store, path).unwrap_or_else(|e| trace_error_exit(&e, 1)); + let path = StoreId::new(store, path).map_err_trace_exit_unwrap(1); debug!("Deleting file at {:?}", id); let _ = rt.store() diff --git a/bin/core/imag-store/src/dump.rs b/bin/core/imag-store/src/dump.rs index e9eae4ee..0de05e24 100644 --- a/bin/core/imag-store/src/dump.rs +++ b/bin/core/imag-store/src/dump.rs @@ -23,28 +23,16 @@ use libimagrt::runtime::Runtime; use libimagerror::trace::*; pub fn dump(rt: &mut Runtime) { - let cachingres = rt - .store() + rt.store() .entries() - .map_err_trace() - .map(|iter| { - for elem in iter { - debug!("Working on {:?}", elem); - if let Ok(_) = rt.store().get(elem.clone()).map_err_dbg_trace() { - info!("Loading entry at {:?} succeeded", elem); - } else { - error!("Loading entry at {:?} failed", elem); - } - } + .map_err_trace_exit_unwrap(1) + .for_each(|elem| { + debug!("Working on {:?}", elem); + rt.store().get(elem).map_err_trace_exit_unwrap(1); }); - if let Ok(_) = cachingres { - if let Err(_) = rt.store_backend_to_stdout().map_err_trace() { - error!("Loading Store IO backend failed"); - exit(1); - } - } else { - error!("Loading entries failed"); + if let Err(_) = rt.store_backend_to_stdout().map_err_trace() { + error!("Loading Store IO backend failed"); exit(1); } } diff --git a/bin/core/imag-store/src/get.rs b/bin/core/imag-store/src/get.rs index bff7b674..b9324fef 100644 --- a/bin/core/imag-store/src/get.rs +++ b/bin/core/imag-store/src/get.rs @@ -20,7 +20,7 @@ use std::path::PathBuf; use libimagrt::runtime::Runtime; -use libimagerror::trace::trace_error_exit; +use libimagerror::trace::MapErrTrace; use libimagstore::storeid::StoreId; use retrieve::print_entry; @@ -31,13 +31,12 @@ pub fn get(rt: &Runtime) { let id = scmd.value_of("id").unwrap(); // safe by clap let path = PathBuf::from(id); let store = Some(rt.store().path().clone()); - let path = StoreId::new(store, path).unwrap_or_else(|e| trace_error_exit(&e, 1)); + let path = StoreId::new(store, path).map_err_trace_exit_unwrap(1); debug!("path = {:?}", path); - let _ = match rt.store().get(path) { - Ok(Some(entry)) => print_entry(rt, scmd, entry), - Ok(None) => info!("No entry found"), - Err(e) => trace_error_exit(&e, 1), + let _ = match rt.store().get(path).map_err_trace_exit_unwrap(1) { + Some(entry) => print_entry(rt, scmd, entry), + None => info!("No entry found"), }; } diff --git a/bin/core/imag-store/src/update.rs b/bin/core/imag-store/src/update.rs index 574b15ef..981c8089 100644 --- a/bin/core/imag-store/src/update.rs +++ b/bin/core/imag-store/src/update.rs @@ -21,7 +21,7 @@ use std::ops::DerefMut; use std::path::PathBuf; use libimagrt::runtime::Runtime; -use libimagerror::trace::trace_error_exit; +use libimagerror::trace::MapErrTrace; use libimagstore::storeid::StoreId; use util::build_toml_header; @@ -31,7 +31,7 @@ pub fn update(rt: &Runtime) { let id = scmd.value_of("id").unwrap(); // Safe by clap let path = PathBuf::from(id); let store = Some(rt.store().path().clone()); - let path = StoreId::new(store, path).unwrap_or_else(|e| trace_error_exit(&e, 1)); + let path = StoreId::new(store, path).map_err_trace_exit_unwrap(1); let _ = rt.store() .retrieve(path)