mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-10-30 16:40:18 +00:00
Replace `println!` calls on the results paths with `writeln!` on `io::stdout()` and propagate the `io::Error` to `main`, where `ErrorKind::BrokenPipe` is turned into a quiet `exit(0)`. This matches the conventional behavior of command-line tools when their output pipe is closed early (e.g. `hyperfine ... | head -n 0`), and fixes panics in all run-output paths: the per-benchmark header and results, the speed comparison summary, and `-`-style exports to stdout. The warnings and "Note" outputs to stderr are converted the same way. --------- Co-authored-by: Mathjk <Mathjk@users.noreply.github.com> Co-authored-by: David Peter <mail@david-peter.de>
63 lines
2.5 KiB
Rust
63 lines
2.5 KiB
Rust
use std::num::{self, ParseFloatError, ParseIntError};
|
|
|
|
use rust_decimal::Error as DecimalError;
|
|
use thiserror::Error;
|
|
|
|
#[derive(Debug, Error)]
|
|
#[error(transparent)]
|
|
pub struct ConsoleOutputError(pub std::io::Error);
|
|
|
|
#[derive(Debug, Error)]
|
|
pub enum ParameterScanError {
|
|
#[error("Error while parsing parameter scan arguments ({0})")]
|
|
ParseIntError(num::ParseIntError),
|
|
#[error("Error while parsing parameter scan arguments ({0})")]
|
|
ParseDecimalError(DecimalError),
|
|
#[error("Empty parameter range")]
|
|
EmptyRange,
|
|
#[error("Parameter range is too large")]
|
|
TooLarge,
|
|
#[error("Zero is not a valid parameter step")]
|
|
ZeroStep,
|
|
#[error("A step size is required when the range bounds are floating point numbers. The step size can be specified with the '-D/--parameter-step-size <DELTA>' parameter")]
|
|
StepRequired,
|
|
#[error("'--command-name' has been specified {0} times. It has to appear exactly once, or exactly {1} times (number of benchmarks)")]
|
|
UnexpectedCommandNameCount(usize, usize),
|
|
}
|
|
|
|
impl From<num::ParseIntError> for ParameterScanError {
|
|
fn from(e: num::ParseIntError) -> ParameterScanError {
|
|
ParameterScanError::ParseIntError(e)
|
|
}
|
|
}
|
|
|
|
impl From<DecimalError> for ParameterScanError {
|
|
fn from(e: DecimalError) -> ParameterScanError {
|
|
ParameterScanError::ParseDecimalError(e)
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Error)]
|
|
pub enum OptionsError<'a> {
|
|
#[error(
|
|
"Conflicting requirements for the number of runs (empty range, min is larger than max)"
|
|
)]
|
|
EmptyRunsRange,
|
|
#[error("Too many --command-name options: Expected {0} at most")]
|
|
TooManyCommandNames(usize),
|
|
#[error("'--command-name' has been specified {0} times. It has to appear exactly once, or exactly {1} times (number of benchmarks)")]
|
|
UnexpectedCommandNameCount(usize, usize),
|
|
#[error("Could not read numeric integer argument to '--{0}': {1}")]
|
|
IntParsingError(&'a str, ParseIntError),
|
|
#[error("Could not read numeric floating point argument to '--{0}': {1}")]
|
|
FloatParsingError(&'a str, ParseFloatError),
|
|
#[error("An empty command has been specified for the '--shell <command>' option")]
|
|
EmptyShell,
|
|
#[error("Failed to parse '--shell <command>' expression as command line: {0}")]
|
|
ShellParseError(shell_words::ParseError),
|
|
#[error("Unknown output policy '{0}'. Use './{0}' to output to a file named '{0}'.")]
|
|
UnknownOutputPolicy(String),
|
|
#[error("The file '{0}' specified as '--input' does not exist")]
|
|
StdinDataFileDoesNotExist(String),
|
|
}
|