1use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, Error>;
7
8#[derive(Error, Debug, Clone, PartialEq, Eq)]
10#[non_exhaustive]
11pub enum Error {
12 #[error("not all read quorums intersect all write quorums")]
14 NonOverlappingQuorums,
15
16 #[error("no strategy found satisfying the constraints")]
19 NoStrategyFound,
20
21 #[error("no quorum system found satisfying the requirements")]
23 NoQuorumSystemFound,
24
25 #[error("invalid distribution: {0}")]
27 InvalidDistribution(String),
28
29 #[error("LP solver error: {0}")]
31 LpError(String),
32
33 #[error("invalid quorum system: {0}")]
35 InvalidQuorumSystem(String),
36
37 #[error("invalid expression: {0}")]
39 InvalidExpression(String),
40}
41
42impl From<good_lp::ResolutionError> for Error {
43 fn from(e: good_lp::ResolutionError) -> Self {
44 match e {
45 good_lp::ResolutionError::Infeasible => Self::NoStrategyFound,
46 other => Self::LpError(other.to_string()),
47 }
48 }
49}
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[test]
56 fn resolution_error_mapping() {
57 assert_eq!(
58 Error::from(good_lp::ResolutionError::Infeasible),
59 Error::NoStrategyFound
60 );
61 assert!(matches!(
62 Error::from(good_lp::ResolutionError::Unbounded),
63 Error::LpError(_)
64 ));
65 assert!(Error::NonOverlappingQuorums.to_string().contains("intersect"));
66 }
67}