Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to return the status code of a failed command #756

Open
Scripter17 opened this issue Jul 3, 2024 · 6 comments
Open

Option to return the status code of a failed command #756

Scripter17 opened this issue Jul 3, 2024 · 6 comments

Comments

@Scripter17
Copy link

For part of a thing I'm working on, I use Hyperfine to benchmark an HTTP server using Curl. If I mess up writing the tests the server can return a 413 "Content Too Large" error and, because Curl is being run with the --fail/-f flag, Curl returns an exit code of 22.

Afterwards the bash script I use for benchmarking checks if Hyperfine returned a non-zero exit code and print some details on what could've gone wrong and what to do to fix it.

It'd be nice if I could tell which exact exit code Curl returned and provide only the necessary solution.

@sharkdp
Copy link
Owner

sharkdp commented Jul 4, 2024

You can use the --export-json option. Exit codes are present in the output.

@Scripter17
Copy link
Author

I can't seem to get that to work. Even just hyperfine "exit 1" --export-json abc.json writes nothing. Having multiple commands where one errors results in that specific command not being written to the json. I am using v1.18.0, which as I write this is the most recent release.

I assume the issue is that the initial measurement (or the warmup if that's enabled) returns an error? Can't exactly write a meaningful mean time in that case.

To clarify, that is what happens when a test in my benchmarking script sends too big a payload to the server. It errors on the first try.

@sharkdp
Copy link
Owner

sharkdp commented Jul 4, 2024

I can't seem to get that to work. Even just hyperfine "exit 1" --export-json abc.json writes nothing.

Oh, you also need:

  -i, --ignore-failure
          Ignore non-zero exit codes of the benchmarked programs.

As written in the error message:

▶ hyperfine "exit 17" --export-json abc.json
Benchmark 1: exit 17
Error: Command terminated with non-zero exit code: 17. Use the '-i'/'--ignore-failure' option if you want to ignore this. Alternatively, use the '--show-output' option to debug what went wrong.

@Scripter17
Copy link
Author

I can make that work since I'm already exporting the json and using jq to get a list of the mean times, but that would be very annoying for anyone who wants a portable script that doesn't depend on either.

@sharkdp
Copy link
Owner

sharkdp commented Jul 16, 2024

I'm not really sure what you're asking for.

@Scripter17
Copy link
Author

hyperfine "exit 4"
echo $? # 1 (current behavior)

hyperfine --return-error "exit 4"
echo $? # 4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants