2019-08-31 12:48:26 +05:30
|
|
|
use rust_decimal::Error as DecimalError;
|
2018-03-24 15:46:28 +01:00
|
|
|
use std::error::Error;
|
|
|
|
|
use std::fmt;
|
2018-05-22 22:57:51 +02:00
|
|
|
use std::num;
|
2020-10-16 23:38:15 +02:00
|
|
|
use std::num::ParseIntError;
|
2018-03-24 15:46:28 +01:00
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
2018-03-24 20:17:17 +01:00
|
|
|
pub enum ParameterScanError {
|
2018-03-24 15:46:28 +01:00
|
|
|
ParseIntError(num::ParseIntError),
|
2019-08-31 12:48:26 +05:30
|
|
|
ParseDecimalError(DecimalError),
|
2018-03-24 15:46:28 +01:00
|
|
|
EmptyRange,
|
|
|
|
|
TooLarge,
|
2019-08-22 00:50:20 +05:30
|
|
|
ZeroStep,
|
2019-08-31 12:48:26 +05:30
|
|
|
StepRequired,
|
2021-07-27 14:24:30 +00:00
|
|
|
UnexpectedCommandNameCount(usize, usize),
|
2018-03-24 15:46:28 +01:00
|
|
|
}
|
|
|
|
|
|
2018-03-24 20:17:17 +01:00
|
|
|
impl From<num::ParseIntError> for ParameterScanError {
|
|
|
|
|
fn from(e: num::ParseIntError) -> ParameterScanError {
|
|
|
|
|
ParameterScanError::ParseIntError(e)
|
2018-03-24 15:46:28 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-31 12:48:26 +05:30
|
|
|
impl From<DecimalError> for ParameterScanError {
|
|
|
|
|
fn from(e: DecimalError) -> ParameterScanError {
|
|
|
|
|
ParameterScanError::ParseDecimalError(e)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-24 20:17:17 +01:00
|
|
|
impl fmt::Display for ParameterScanError {
|
2019-05-07 11:55:38 +02:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
2018-09-09 14:10:36 +01:00
|
|
|
match *self {
|
2019-12-15 23:47:53 +01:00
|
|
|
ParameterScanError::ParseIntError(ref e) => write!(f, "{}", e),
|
|
|
|
|
ParameterScanError::ParseDecimalError(ref e) => write!(f, "{}", e),
|
|
|
|
|
ParameterScanError::EmptyRange => write!(f, "Empty parameter range"),
|
|
|
|
|
ParameterScanError::TooLarge => write!(f, "Parameter range is too large"),
|
|
|
|
|
ParameterScanError::ZeroStep => write!(f, "Zero is not a valid parameter step"),
|
|
|
|
|
ParameterScanError::StepRequired => write!(
|
|
|
|
|
f,
|
2019-09-01 16:00:53 +05:30
|
|
|
"A step size is required when the range bounds are \
|
|
|
|
|
floating point numbers. The step size can be specified \
|
|
|
|
|
with the '--parameter-step-size' parameter"
|
2019-12-15 23:47:53 +01:00
|
|
|
),
|
2021-07-27 14:24:30 +00:00
|
|
|
ParameterScanError::UnexpectedCommandNameCount(real, expected) => {
|
2021-05-13 05:54:25 +00:00
|
|
|
write!(
|
|
|
|
|
f,
|
2021-07-27 14:24:30 +00:00
|
|
|
"'--command-name' has been specified {} times. It has to appear exactly once, or exactly {} times (number of benchmarks)",
|
2021-05-13 05:54:25 +00:00
|
|
|
real, expected
|
|
|
|
|
)
|
|
|
|
|
}
|
2018-09-09 14:10:36 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-15 23:47:53 +01:00
|
|
|
impl Error for ParameterScanError {}
|
|
|
|
|
|
2018-09-09 14:10:36 +01:00
|
|
|
#[derive(Debug)]
|
2020-10-16 23:38:15 +02:00
|
|
|
pub enum OptionsError<'a> {
|
2018-09-09 14:10:36 +01:00
|
|
|
RunsBelowTwo,
|
|
|
|
|
EmptyRunsRange,
|
2020-10-15 22:32:30 +02:00
|
|
|
TooManyCommandNames(usize),
|
2021-07-27 14:24:30 +00:00
|
|
|
UnexpectedCommandNameCount(usize, usize),
|
2020-10-16 23:38:15 +02:00
|
|
|
NumericParsingError(&'a str, ParseIntError),
|
2018-09-09 14:10:36 +01:00
|
|
|
}
|
|
|
|
|
|
2020-10-16 23:38:15 +02:00
|
|
|
impl<'a> fmt::Display for OptionsError<'a> {
|
2019-05-07 11:55:38 +02:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
2018-09-09 14:10:36 +01:00
|
|
|
match *self {
|
2019-12-15 23:47:53 +01:00
|
|
|
OptionsError::EmptyRunsRange => write!(f, "Empty runs range"),
|
|
|
|
|
OptionsError::RunsBelowTwo => write!(f, "Number of runs below two"),
|
2020-10-15 22:32:30 +02:00
|
|
|
OptionsError::TooManyCommandNames(n) => {
|
|
|
|
|
write!(f, "Too many --command-name options: expected {} at most", n)
|
|
|
|
|
}
|
2021-07-27 14:24:30 +00:00
|
|
|
OptionsError::UnexpectedCommandNameCount(real, expected) => {
|
2021-05-13 05:54:25 +00:00
|
|
|
write!(
|
|
|
|
|
f,
|
2021-07-27 14:24:30 +00:00
|
|
|
"'--command-name' has been specified {} times. It has to appear exactly once, or exactly {} times (number of benchmarks)",
|
2021-05-13 05:54:25 +00:00
|
|
|
real, expected
|
|
|
|
|
)
|
|
|
|
|
}
|
2020-10-16 23:38:15 +02:00
|
|
|
OptionsError::NumericParsingError(cmd, ref err) => write!(
|
|
|
|
|
f,
|
|
|
|
|
"Could not read numeric argument to '--{cmd}': {err}",
|
|
|
|
|
cmd = cmd,
|
|
|
|
|
err = err
|
|
|
|
|
),
|
2018-09-09 14:10:36 +01:00
|
|
|
}
|
2018-03-24 15:46:28 +01:00
|
|
|
}
|
|
|
|
|
}
|
2019-12-15 23:47:53 +01:00
|
|
|
|
2020-10-16 23:38:15 +02:00
|
|
|
impl<'a> Error for OptionsError<'a> {}
|