From 94c7c51865340c645c6e240f7e043b44d6755405 Mon Sep 17 00:00:00 2001 From: Alexander Thaller Date: Thu, 2 Sep 2021 15:11:55 +0200 Subject: [PATCH] Don't print an error if the pipe is closed (#20) --- src/main.rs | 11 +++++++++-- src/run/mod.rs | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1c39113..76f0384 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,7 +19,14 @@ use structopt::StructOpt; fn main() { let opt = Opt::from_args(); - if let Err(err) = opt.run() { - error!("{}", err); + match opt.run() { + Err(run::Error::WriteStdout(io_err)) => { + // If pipe is closed we can savely ignore that error + if io_err.kind() == std::io::ErrorKind::BrokenPipe {} + } + + Err(err) => error!("{}", err), + + Ok(_) => (), } } diff --git a/src/run/mod.rs b/src/run/mod.rs index ec49626..7e3c0da 100644 --- a/src/run/mod.rs +++ b/src/run/mod.rs @@ -182,6 +182,7 @@ pub fn default_no_format(display: &TableDisplay, entries: Vec) -> Result< handle .write_all(header.join("\t").as_bytes()) .map_err(Error::WriteStdout)?; + handle.write_all(b"\n").map_err(Error::WriteStdout)?; } @@ -212,6 +213,7 @@ pub fn default_no_format(display: &TableDisplay, entries: Vec) -> Result< handle .write_all(row.join("\t").as_bytes()) .map_err(Error::WriteStdout)?; + handle.write_all(b"\n").map_err(Error::WriteStdout)?; }