From 6ab5d1d880be5e4a0b596f3954e8b5ecf01dde25 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 19 Oct 2019 08:54:57 +0200 Subject: [PATCH] Remove calls to exit() and replace them with error propagation up to main() Signed-off-by: Matthias Beyer --- bin/core/imag-create/src/lib.rs | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/bin/core/imag-create/src/lib.rs b/bin/core/imag-create/src/lib.rs index 9e7b607a..ced6e0ac 100644 --- a/bin/core/imag-create/src/lib.rs +++ b/bin/core/imag-create/src/lib.rs @@ -36,21 +36,19 @@ extern crate clap; extern crate failure; -#[macro_use] extern crate log; extern crate libimagerror; extern crate libimagrt; extern crate libimagstore; use failure::Fallible as Result; +use failure::err_msg; use clap::App; use libimagrt::runtime::Runtime; use libimagrt::application::ImagApplication; -use libimagerror::trace::MapErrTrace; use libimagstore::iter::create::StoreIdCreateIteratorExtension; use libimagstore::iter::retrieve::StoreIdRetrieveIteratorExtension; -use libimagerror::exit::ExitUnwrap; mod ui; @@ -60,30 +58,17 @@ pub enum ImagCreate {} impl ImagApplication for ImagCreate { fn run(rt: Runtime) -> Result<()> { let force = rt.cli().is_present("force"); - debug!("Detected force = {}", force); - let ids = rt.ids::() - .map_err_trace_exit_unwrap() - .unwrap_or_else(|| { - error!("No ids supplied"); - ::std::process::exit(1); - }) + let ids = rt.ids::()? + .ok_or_else(|| err_msg("No ids supplied"))? .into_iter() - .map(|id| { debug!("id = {}", id); id }) .map(Ok); if force { ids.into_retrieve_iter(rt.store()).collect::>>() } else { ids.into_create_iter(rt.store()).collect::>>() - }.map_err_trace_exit_unwrap() - .into_iter() - .for_each(|el| { - rt.report_touched(el.get_location()).unwrap_or_exit(); - trace!("Entry = {}", el.get_location()); - }); - - Ok(()) + }.map(|_| ()) } fn build_cli<'a>(app: App<'a, 'a>) -> App<'a, 'a> {