use std::error::Error;
use std::fmt;
use crate::OperationLifecycle;
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum MetricError {
OperationNotOpen {
metric_id: String,
state: OperationLifecycle,
},
InsufficientActive {
metric_id: String,
requested: u64,
available: u64,
},
TotalExceeded {
metric_id: String,
total: u64,
attempted: u64,
},
CountOverflow {
metric_id: String,
},
}
impl fmt::Display for MetricError {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::OperationNotOpen { metric_id, state } => write!(
formatter,
"metric {metric_id:?} is not open because operation is {state:?}"
),
Self::InsufficientActive {
metric_id,
requested,
available,
} => write!(
formatter,
"metric {metric_id:?} cannot complete {requested} work items because only {available} are active"
),
Self::TotalExceeded {
metric_id,
total,
attempted,
} => write!(
formatter,
"metric {metric_id:?} would occupy {attempted} work items above total {total}"
),
Self::CountOverflow { metric_id } => {
write!(formatter, "counts for metric {metric_id:?} overflowed")
}
}
}
}
impl Error for MetricError {}