From c05d7f94808449108785708d9a99e8fdc07fa5dc Mon Sep 17 00:00:00 2001 From: Julian Kaindl Date: Sun, 25 Oct 2020 19:04:17 +0100 Subject: [PATCH] Add command exit code to output if it fails --- CHANGELOG.md | 2 ++ src/hyperfine/benchmark.rs | 12 +++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d511387..a0599f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # unreleased +- Add command exit code to output if it fails, see #342 (@KaindlJulian) + ## Features ## Changes diff --git a/src/hyperfine/benchmark.rs b/src/hyperfine/benchmark.rs index db885c9..446d75d 100644 --- a/src/hyperfine/benchmark.rs +++ b/src/hyperfine/benchmark.rs @@ -63,9 +63,15 @@ pub fn time_shell_command( if failure_action == CmdFailureAction::RaiseError && !result.status.success() { return Err(io::Error::new( io::ErrorKind::Other, - "Command terminated with non-zero exit code. \ - Use the '-i'/'--ignore-failure' option if you want to ignore this. \ - Alternatively, use the '--show-output' option to debug what went wrong.", + format!( + "{}. \ + Use the '-i'/'--ignore-failure' option if you want to ignore this. \ + Alternatively, use the '--show-output' option to debug what went wrong.", + result.status.code().map_or( + "The process has been terminated by a signal".into(), + |c| format!("Command terminated with non-zero exit code: {}", c) + ) + ), )); }