use core::fmt;
use std::time::Duration;
use crate::ordering::Ordering;
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub enum ConfigError {
ZeroInFlight,
ZeroBatchSize,
ZeroPollInterval {
field: &'static str,
},
StoreTimeoutTooLong {
store_timeout: Duration,
lease: Duration,
},
LeaseTooShort {
lease: Duration,
publish_timeout: Duration,
},
UnsupportedOrdering {
ordering: Ordering,
available_in: &'static str,
},
InvalidJitter {
value: f64,
},
ZeroMaxAttempts,
ZeroRetryBase,
RetryPolicyConflict,
}
impl fmt::Display for ConfigError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::ZeroInFlight => f.write_str("max_in_flight must be greater than zero"),
Self::ZeroBatchSize => f.write_str("batch_size must be greater than zero"),
Self::ZeroPollInterval { field } => write!(f, "{field} must be greater than zero"),
Self::StoreTimeoutTooLong { store_timeout, lease } => write!(
f,
"store_timeout ({store_timeout:?}) must be shorter than half the lease \
({lease:?}) — a hung outcome write must not be able to occupy a whole \
renewal-tick gap"
),
Self::LeaseTooShort {
lease,
publish_timeout,
} => write!(
f,
"lease ({lease:?}) must be longer than publish_timeout ({publish_timeout:?})"
),
Self::UnsupportedOrdering {
ordering,
available_in,
} => write!(
f,
"{ordering:?} ordering is not implemented until {available_in}"
),
Self::InvalidJitter { value } => {
write!(f, "jitter {value} must be in the range [0.0, 1.0)")
}
Self::ZeroMaxAttempts => f.write_str("max_attempts must be at least 1"),
Self::ZeroRetryBase => f.write_str("base delay must be greater than zero"),
Self::RetryPolicyConflict => f.write_str(
"a custom retry policy was supplied together with a non-default DispatcherSettings::retry; leave settings.retry at its default or feed it to the custom policy yourself",
),
}
}
}
impl std::error::Error for ConfigError {}