From 876c1cb9af42b8fca1fa007a11d7658f4a242b7f Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 14 Feb 2018 18:33:28 +0100 Subject: [PATCH] Fix broken pipe panics --- bin/domain/imag-diary/src/main.rs | 7 +++++-- bin/domain/imag-mail/src/main.rs | 9 +++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/bin/domain/imag-diary/src/main.rs b/bin/domain/imag-diary/src/main.rs index 1ed42666..ca13cf24 100644 --- a/bin/domain/imag-diary/src/main.rs +++ b/bin/domain/imag-diary/src/main.rs @@ -50,6 +50,8 @@ extern crate libimagutil; use std::process::exit; +use libimagerror::exit::ExitUnwrap; +use libimagerror::io::ToExitCode; use libimagrt::runtime::Runtime; mod create; @@ -77,8 +79,9 @@ fn main() { if rt.is_ok() { rt.unwrap() } else { - println!("Could not set up Runtime"); - println!("{:?}", rt.err().unwrap()); + let mut out = ::std::io::stdout(); + let _ = writeln!(out, "Could not set up Runtime").to_exit_code().unwrap_or_exit(); + let _ = writeln!(out, "{:?}", rt.err().unwrap()).to_exit_code().unwrap_or_exit(); exit(1); } }; diff --git a/bin/domain/imag-mail/src/main.rs b/bin/domain/imag-mail/src/main.rs index 6a018f94..b822aeba 100644 --- a/bin/domain/imag-mail/src/main.rs +++ b/bin/domain/imag-mail/src/main.rs @@ -25,7 +25,11 @@ extern crate libimagmail; extern crate libimagerror; extern crate libimagutil; +use std::io::Write; + use libimagerror::trace::{MapErrTrace, trace_error}; +use libimagerror::exit::ExitUnwrap; +use libimagerror::io::ToExitCode; use libimagmail::mail::Mail; use libimagrt::runtime::Runtime; use libimagrt::setup::generate_runtime_setup; @@ -106,12 +110,13 @@ fn list(rt: &Runtime) { }, }; - println!("Mail: {id}\n\tFrom: {from}\n\tTo: {to}\n\t{subj}\n", + writeln!(::std::io::stdout(), + "Mail: {id}\n\tFrom: {from}\n\tTo: {to}\n\t{subj}\n", from = from, id = id, subj = subject, to = to - ); + ).to_exit_code().unwrap_or_exit() } let _ = rt.store()