use thiserror::Error;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Error, Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum Error {
#[error("not all read quorums intersect all write quorums")]
NonOverlappingQuorums,
#[error("no strategy found satisfying the constraints")]
NoStrategyFound,
#[error("no quorum system found satisfying the requirements")]
NoQuorumSystemFound,
#[error("invalid distribution: {0}")]
InvalidDistribution(String),
#[error("LP solver error: {0}")]
LpError(String),
#[error("invalid quorum system: {0}")]
InvalidQuorumSystem(String),
#[error("invalid expression: {0}")]
InvalidExpression(String),
}
impl From<good_lp::ResolutionError> for Error {
fn from(e: good_lp::ResolutionError) -> Self {
match e {
good_lp::ResolutionError::Infeasible => Self::NoStrategyFound,
other => Self::LpError(other.to_string()),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn resolution_error_mapping() {
assert_eq!(
Error::from(good_lp::ResolutionError::Infeasible),
Error::NoStrategyFound
);
assert!(matches!(
Error::from(good_lp::ResolutionError::Unbounded),
Error::LpError(_)
));
assert!(Error::NonOverlappingQuorums.to_string().contains("intersect"));
}
}