error.rs
This file
Path
src/error.rs
96 lines · 3.3 KiB · Rust
Last changed by
Add support for one run with --runs=1Ævar Arnfjörð Bjarmasonbefore adoptionbffd476
History of this fileTake it
Flat directory/module structureDavid Peterbefore adoption30c381f
lines 1–4why, one step back1use std::error::Error;2use std::fmt;3use std::num;4use std::num::ParseIntError;Re-order importsDavid Peterbefore adoption9df6174
lines 5–6why, one step back56use rust_decimal::Error as DecimalError;Flat directory/module structureDavid Peterbefore adoption30c381f
lines 7–63why, one step back78#[derive(Debug)]9pub enum ParameterScanError {10 ParseIntError(num::ParseIntError),11 ParseDecimalError(DecimalError),12 EmptyRange,13 TooLarge,14 ZeroStep,15 StepRequired,16 UnexpectedCommandNameCount(usize, usize),17}1819impl From<num::ParseIntError> for ParameterScanError {20 fn from(e: num::ParseIntError) -> ParameterScanError {21 ParameterScanError::ParseIntError(e)22 }23}2425impl From<DecimalError> for ParameterScanError {26 fn from(e: DecimalError) -> ParameterScanError {27 ParameterScanError::ParseDecimalError(e)28 }29}3031impl fmt::Display for ParameterScanError {32 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {33 match *self {34 ParameterScanError::ParseIntError(ref e) => write!(f, "{}", e),35 ParameterScanError::ParseDecimalError(ref e) => write!(f, "{}", e),36 ParameterScanError::EmptyRange => write!(f, "Empty parameter range"),37 ParameterScanError::TooLarge => write!(f, "Parameter range is too large"),38 ParameterScanError::ZeroStep => write!(f, "Zero is not a valid parameter step"),39 ParameterScanError::StepRequired => write!(40 f,41 "A step size is required when the range bounds are \42 floating point numbers. The step size can be specified \43 with the '--parameter-step-size' parameter"44 ),45 ParameterScanError::UnexpectedCommandNameCount(real, expected) => {46 write!(47 f,48 "'--command-name' has been specified {} times. It has to appear exactly once, or exactly {} times (number of benchmarks)",49 real, expected50 )51 }52 }53 }54}5556impl Error for ParameterScanError {}5758#[derive(Debug)]59pub enum OptionsError<'a> {60 EmptyRunsRange,61 TooManyCommandNames(usize),62 UnexpectedCommandNameCount(usize, usize),63 NumericParsingError(&'a str, ParseIntError),Parse --shell option value as shell commandrhysdbefore adoptione2fdace
lines 64–65why, one step back64 EmptyShell,65 ShellParseError(shell_words::ParseError),Flat directory/module structureDavid Peterbefore adoption30c381f
lines 66–87why, one step back66}6768impl<'a> fmt::Display for OptionsError<'a> {69 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {70 match *self {71 OptionsError::EmptyRunsRange => write!(f, "Empty runs range"),72 OptionsError::TooManyCommandNames(n) => {73 write!(f, "Too many --command-name options: expected {} at most", n)74 }75 OptionsError::UnexpectedCommandNameCount(real, expected) => {76 write!(77 f,78 "'--command-name' has been specified {} times. It has to appear exactly once, or exactly {} times (number of benchmarks)",79 real, expected80 )81 }82 OptionsError::NumericParsingError(cmd, ref err) => write!(83 f,84 "Could not read numeric argument to '--{cmd}': {err}",85 cmd = cmd,86 err = err87 ),Parse --shell option value as shell commandrhysdbefore adoptione2fdace
lines 88–91why, one step back88 OptionsError::EmptyShell => write!(f, "Empty command at --shell option"),89 OptionsError::ShellParseError(ref err) => {90 write!(f, "Could not parse --shell value as command line: {}", err)91 }Flat directory/module structureDavid Peterbefore adoption30c381f
lines 92–96why, one step back92 }93 }94}9596impl<'a> Error for OptionsError<'a> {}