use std::fmt;
pub type CounterError = async_nats::error::Error<CounterErrorKind>;
pub type Result<T> = std::result::Result<T, CounterError>;
#[derive(Debug, Clone, PartialEq)]
pub enum CounterErrorKind {
CounterNotEnabled,
DirectAccessRequired,
InvalidCounterValue,
CounterNotFound,
NoCounterForSubject,
InvalidResponseValue,
MissingResponseValue,
InvalidSources,
Serialization,
Stream,
Publish,
GetStream,
Request,
Other,
}
impl fmt::Display for CounterErrorKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::CounterNotEnabled => {
write!(
f,
"stream is not configured for counters (AllowMsgCounter must be true)"
)
}
Self::DirectAccessRequired => {
write!(
f,
"stream must be configured for direct access (AllowDirect must be true)"
)
}
Self::InvalidCounterValue => write!(f, "invalid counter value"),
Self::CounterNotFound => write!(f, "counter not found"),
Self::NoCounterForSubject => write!(f, "counter not initialized for subject"),
Self::InvalidResponseValue => write!(f, "invalid counter value in response"),
Self::MissingResponseValue => write!(f, "counter increment response missing value"),
Self::InvalidSources => write!(f, "failed to parse counter sources"),
Self::Serialization => write!(f, "serialization error"),
Self::Stream => write!(f, "stream operation error"),
Self::Publish => write!(f, "publish operation error"),
Self::GetStream => write!(f, "get stream error"),
Self::Request => write!(f, "request error"),
Self::Other => write!(f, "other error"),
}
}
}