Skip to content
Myr

error.rs

This file

Path

src/error.rs

91 lines · 3.1 KiB · Rust

Last changed by

Flat directory/module structureDavid Peterbefore adoption30c381f

History of this file

Take it

Flat directory/module structureDavid Peterbefore adoption30c381f

lines 1–91why, one step back
1use rust_decimal::Error as DecimalError;
2use std::error::Error;3use std::fmt;4use std::num;5use std::num::ParseIntError;67#[derive(Debug)]8pub enum ParameterScanError {9 ParseIntError(num::ParseIntError),10 ParseDecimalError(DecimalError),11 EmptyRange,12 TooLarge,13 ZeroStep,14 StepRequired,15 UnexpectedCommandNameCount(usize, usize),16}1718impl From<num::ParseIntError> for ParameterScanError {19 fn from(e: num::ParseIntError) -> ParameterScanError {20 ParameterScanError::ParseIntError(e)21 }22}2324impl From<DecimalError> for ParameterScanError {25 fn from(e: DecimalError) -> ParameterScanError {26 ParameterScanError::ParseDecimalError(e)27 }28}2930impl fmt::Display for ParameterScanError {31 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {32 match *self {33 ParameterScanError::ParseIntError(ref e) => write!(f, "{}", e),34 ParameterScanError::ParseDecimalError(ref e) => write!(f, "{}", e),35 ParameterScanError::EmptyRange => write!(f, "Empty parameter range"),36 ParameterScanError::TooLarge => write!(f, "Parameter range is too large"),37 ParameterScanError::ZeroStep => write!(f, "Zero is not a valid parameter step"),38 ParameterScanError::StepRequired => write!(39 f,40 "A step size is required when the range bounds are \41 floating point numbers. The step size can be specified \42 with the '--parameter-step-size' parameter"43 ),44 ParameterScanError::UnexpectedCommandNameCount(real, expected) => {45 write!(46 f,47 "'--command-name' has been specified {} times. It has to appear exactly once, or exactly {} times (number of benchmarks)",48 real, expected49 )50 }51 }52 }53}5455impl Error for ParameterScanError {}5657#[derive(Debug)]58pub enum OptionsError<'a> {59 RunsBelowTwo,60 EmptyRunsRange,61 TooManyCommandNames(usize),62 UnexpectedCommandNameCount(usize, usize),63 NumericParsingError(&'a str, ParseIntError),64}6566impl<'a> fmt::Display for OptionsError<'a> {67 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {68 match *self {69 OptionsError::EmptyRunsRange => write!(f, "Empty runs range"),70 OptionsError::RunsBelowTwo => write!(f, "Number of runs below two"),71 OptionsError::TooManyCommandNames(n) => {72 write!(f, "Too many --command-name options: expected {} at most", n)73 }74 OptionsError::UnexpectedCommandNameCount(real, expected) => {75 write!(76 f,77 "'--command-name' has been specified {} times. It has to appear exactly once, or exactly {} times (number of benchmarks)",78 real, expected79 )80 }81 OptionsError::NumericParsingError(cmd, ref err) => write!(82 f,83 "Could not read numeric argument to '--{cmd}': {err}",84 cmd = cmd,85 err = err86 ),87 }88 }89}9091impl<'a> Error for OptionsError<'a> {}