From 1891e125701f312be3bf5eb1857141e068dd365b Mon Sep 17 00:00:00 2001 From: Trey Aspelund Date: Fri, 2 Aug 2024 13:32:15 -0600 Subject: [PATCH] cli: handle EPIPE for version subcommand MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit EPIPE handling was added recently via {e}println_nopipe() macros, but wasn't used for the "version" subcommand. This replaces println() calls with println_nopipe(). Before: ``` ➜ oxide.rs git:(main) ./target/debug/oxide version | head -1 Oxide CLI 0.6.1+20240710.0 ➜ oxide.rs git:(main) ./target/debug/oxide version | a zsh: command not found: a thread 'tokio-runtime-worker' panicked at library/std/src/io/stdio.rs:1021:9: failed printing to stdout: Broken pipe (os error 32) note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace thread 'main' panicked at cli/src/main.rs:105:10: called `Result::unwrap()` on an `Err` value: JoinError::Panic(Id(9), ...) ➜ oxide.rs git:(main) ``` After: ``` ➜ oxide.rs git:(trey/epipe_version) ./target/debug/oxide version | head -1 Oxide CLI 0.6.1+20240710.0 ➜ oxide.rs git:(trey/epipe_version) ./target/debug/oxide version | a zsh: command not found: a ➜ oxide.rs git:(trey/epipe_version) ``` Fixes: #773 Signed-off-by: Trey Aspelund --- cli/src/cmd_version.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cli/src/cmd_version.rs b/cli/src/cmd_version.rs index 6e143ab9..4312c02a 100644 --- a/cli/src/cmd_version.rs +++ b/cli/src/cmd_version.rs @@ -9,6 +9,7 @@ use async_trait::async_trait; use clap::Parser; use oxide::Client; +use crate::println_nopipe; use crate::{context::Context, RunnableCmd}; pub mod built_info { @@ -27,9 +28,9 @@ impl RunnableCmd for CmdVersion { let cli_version = built_info::PKG_VERSION; let api_version = Client::new("").api_version(); - println!("Oxide CLI {}", cli_version); + println_nopipe!("Oxide CLI {}", cli_version); - println!( + println_nopipe!( "Built from commit: {} {}", built_info::GIT_COMMIT_HASH.unwrap(), if matches!(built_info::GIT_DIRTY, Some(true)) { @@ -39,7 +40,7 @@ impl RunnableCmd for CmdVersion { } ); - println!("Oxide API: {}", api_version); + println_nopipe!("Oxide API: {}", api_version); Ok(()) }