Remove calls to exit() and replace them with error propagation up to main()

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
Matthias Beyer 2019-10-19 08:54:57 +02:00
parent f881f44d06
commit 0e74225094

View file

@ -51,12 +51,12 @@ extern crate libimagstore;
use std::io::Write; use std::io::Write;
use filters::filter::Filter; use filters::filter::Filter;
use failure::Fallible as Result;
use failure::Error;
use failure::err_msg;
use libimagstore::storeid::StoreId; use libimagstore::storeid::StoreId;
use libimagrt::setup::generate_runtime_setup; use libimagrt::setup::generate_runtime_setup;
use libimagerror::trace::MapErrTrace;
use libimagerror::exit::ExitUnwrap;
use libimagerror::io::ToExitCode;
mod ui; mod ui;
@ -83,7 +83,7 @@ impl<'a, A> Filter<StoreId> for IsInCollectionsFilter<'a, A>
} }
fn main() { fn main() -> Result<()> {
let version = make_imag_version!(); let version = make_imag_version!();
let rt = generate_runtime_setup("imag-id-in-collection", let rt = generate_runtime_setup("imag-id-in-collection",
&version, &version,
@ -99,22 +99,19 @@ fn main() {
let mut stdout = rt.stdout(); let mut stdout = rt.stdout();
trace!("Got output: {:?}", stdout); trace!("Got output: {:?}", stdout);
rt.ids::<crate::ui::PathProvider>()?
rt.ids::<crate::ui::PathProvider>() .ok_or_else(|| err_msg("No ids supplied"))?
.map_err_trace_exit_unwrap()
.unwrap_or_else(|| {
error!("No ids supplied");
::std::process::exit(1);
})
.iter() .iter()
.filter(|id| collection_filter.filter(id)) .filter(|id| collection_filter.filter(id))
.for_each(|id| { .map(|id| {
rt.report_touched(&id).unwrap_or_exit();
if !rt.output_is_pipe() { if !rt.output_is_pipe() {
let id = id.to_str().map_err_trace_exit_unwrap(); let id = id.to_str()?;
trace!("Writing to {:?}", stdout); trace!("Writing to {:?}", stdout);
writeln!(stdout, "{}", id).to_exit_code().unwrap_or_exit(); writeln!(stdout, "{}", id)?;
} }
rt.report_touched(&id).map_err(Error::from)
}) })
.collect()
} }