use std::{
error::Error,
fmt,
};
#[derive(Clone, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum ConfigurationError {
NoMetrics,
EmptyMetricId {
index: usize,
},
EmptyMetricName {
metric_id: String,
},
DuplicateMetricId {
metric_id: String,
},
EmptyAttributeKey {
key: String,
},
EmptyStageId,
EmptyStageName,
IncompleteStagePosition,
InvalidStagePosition {
position: u64,
total: u64,
},
}
impl fmt::Display for ConfigurationError {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::NoMetrics => formatter
.write_str("a progress operation requires at least one metric"),
Self::EmptyMetricId { index } => {
write!(formatter, "metric at index {index} has an empty ID")
}
Self::EmptyMetricName { metric_id } => {
write!(formatter, "metric {metric_id:?} has an empty name")
}
Self::DuplicateMetricId { metric_id } => {
write!(formatter, "metric ID {metric_id:?} is duplicated")
}
Self::EmptyAttributeKey { key } => {
write!(formatter, "operation attribute key {key:?} is empty")
}
Self::EmptyStageId => formatter.write_str("stage ID is empty"),
Self::EmptyStageName => formatter.write_str("stage name is empty"),
Self::IncompleteStagePosition => formatter.write_str(
"stage position and total must be supplied together",
),
Self::InvalidStagePosition { position, total } => write!(
formatter,
"stage position {position} is outside 1..={total}"
),
}
}
}
impl Error for ConfigurationError {}