use std::time::Duration;
use thiserror::Error;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, Error)]
pub enum Error {
#[error("resource `{resource}` is already locked")]
Contended {
resource: String,
},
#[error("timed out after {waited:?} waiting for `{resource}`")]
Timeout {
resource: String,
waited: Duration,
},
#[error("fencing token {token} for `{resource}` is stale (current: {current})")]
StaleToken {
resource: String,
token: u64,
current: u64,
},
#[error("lease for `{resource}` expired (guard poisoned)")]
LeaseExpired {
resource: String,
},
#[error("cluster error: {0}")]
Cluster(String),
#[error("invalid configuration: {0}")]
Config(String),
}
impl Error {
#[cfg_attr(
not(any(test, feature = "ash-time", feature = "etcd")),
allow(dead_code)
)]
pub(crate) fn cluster(msg: impl Into<String>) -> Self {
Error::Cluster(msg.into())
}
}