waratah_partition/
error.rs1use thiserror::Error;
4use tonic::Status;
5use waratah_proto::ProtoError;
6use waratah_stats::StatsError;
7use waratah_storage::{IndexPermutation, PartitionAxis, StorageError};
8
9#[derive(Debug, Error)]
11pub enum PartitionError {
12 #[error("request targets partition axis {requested}, but this process owns {owned}")]
14 AxisMismatch {
15 requested: PartitionAxis,
17 owned: PartitionAxis,
19 },
20
21 #[error(transparent)]
23 Storage(#[from] StorageError),
24
25 #[error(transparent)]
27 Stats(#[from] StatsError),
28
29 #[error(transparent)]
31 Text(#[from] waratah_text_index::TextIndexError),
32
33 #[error("partition state lock poisoned")]
35 LockPoisoned,
36
37 #[error(transparent)]
39 Proto(#[from] ProtoError),
40
41 #[error("{0} permutation is not owned by this process's axis ({1})")]
44 ScanPermutationNotOwned(&'static str, PartitionAxis),
45
46 #[error("{rpc} does not serve permutation {permutation:?}")]
49 UnsupportedPermutation {
50 rpc: &'static str,
52 permutation: IndexPermutation,
54 },
55
56 #[error("{0} requires an explicit index permutation")]
58 PermutationRequired(&'static str),
59
60 #[error("DomainScan constraint list exceeds the PUSHDOWN_TERMS_LIMIT terms limit ({0})")]
62 DomainScanTooLarge(usize),
63
64 #[error(
66 "DomainScanCounts count mode is incompatible with the request (DistinctGraphs requires merge_default_graph unset)"
67 )]
68 InvalidCountMode,
69
70 #[error(
77 "text subject request sets subject_equals_graph and merge_default_graph together; \
78 the merge removes the graph identity the equality test needs"
79 )]
80 SubjectEqualsGraphWithMerge,
81
82 #[error("listen failed: {0}")]
84 Listen(#[from] std::io::Error),
85
86 #[error("transport error: {0}")]
88 Transport(#[from] tonic::transport::Error),
89}
90
91impl From<PartitionError> for Status {
92 fn from(error: PartitionError) -> Self {
93 let message = error.to_string();
94 match error {
95 PartitionError::AxisMismatch { .. }
96 | PartitionError::Storage(StorageError::PermutationNotOwned { .. }) => {
97 Self::failed_precondition(message)
98 }
99 PartitionError::Storage(StorageError::CatalogNotOnAxis(_))
100 | PartitionError::ScanPermutationNotOwned(_, _) => Self::unimplemented(message),
101 PartitionError::Storage(StorageError::InvalidCatalogGraph(_))
102 | PartitionError::Storage(StorageError::Corrupt(_))
103 | PartitionError::UnsupportedPermutation { .. }
104 | PartitionError::PermutationRequired(_)
105 | PartitionError::DomainScanTooLarge(_)
106 | PartitionError::InvalidCountMode
107 | PartitionError::SubjectEqualsGraphWithMerge
108 | PartitionError::Proto(_) => Self::invalid_argument(message),
109 PartitionError::Text(
110 waratah_text_index::TextIndexError::CandidateLimitExceeded { .. }
111 | waratah_text_index::TextIndexError::SubjectLimitExceeded { .. },
112 ) => Self::resource_exhausted(message),
113 PartitionError::Text(
114 waratah_text_index::TextIndexError::SchemaMismatch
115 | waratah_text_index::TextIndexError::Config(_),
116 ) => Self::failed_precondition(message),
117 PartitionError::Text(waratah_text_index::TextIndexError::EmptyPattern) => {
118 Self::invalid_argument(message)
119 }
120 _ => Self::internal(message),
121 }
122 }
123}