1use std::fmt::Debug;
13
14use timely::progress::{Antichain, Timestamp};
15
16use crate::ShardId;
17
18#[derive(Debug)]
20#[cfg_attr(any(test, debug_assertions), derive(PartialEq))]
21pub enum InvalidUsage<T> {
22 IncompatibleVersion {
24 version: semver::Version,
26 },
27 InvalidBounds {
29 lower: Antichain<T>,
31 upper: Antichain<T>,
33 },
34 InvalidEmptyTimeInterval {
36 lower: Antichain<T>,
38 upper: Antichain<T>,
40 keys: Vec<String>,
42 },
43 InvalidBatchBounds {
45 batch_lower: Antichain<T>,
47 batch_upper: Antichain<T>,
49 append_lower: Antichain<T>,
51 append_upper: Antichain<T>,
53 },
54 UpdateNotBeyondLower {
56 ts: T,
58 lower: Antichain<T>,
60 },
61 UpdateBeyondUpper {
63 ts: T,
65 expected_upper: Antichain<T>,
67 },
68 BatchNotFromThisShard {
71 batch_shard: ShardId,
73 handle_shard: ShardId,
75 },
76 FinalizationError {
78 since: Antichain<T>,
80 upper: Antichain<T>,
82 },
83 CodecMismatch(Box<CodecMismatch>),
85 InvalidRewrite(String),
87}
88
89impl<T: Debug> std::fmt::Display for InvalidUsage<T> {
90 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
91 match self {
92 InvalidUsage::IncompatibleVersion { version } => {
93 write!(f, "incompatible with data version {}", version)
94 }
95 InvalidUsage::InvalidBounds { lower, upper } => {
96 write!(f, "invalid bounds [{:?}, {:?})", lower, upper)
97 }
98 InvalidUsage::InvalidEmptyTimeInterval { lower, upper, keys } => {
99 write!(
100 f,
101 "invalid empty time interval [{:?}, {:?} {:?})",
102 lower, upper, keys
103 )
104 }
105 InvalidUsage::InvalidBatchBounds {
106 batch_lower,
107 batch_upper,
108 append_lower,
109 append_upper,
110 } => {
111 write!(
112 f,
113 "invalid batch bounds [{:?}, {:?}) for append call with [{:?}, {:?})",
114 batch_lower, batch_upper, append_lower, append_upper
115 )
116 }
117 InvalidUsage::UpdateNotBeyondLower { ts, lower } => {
118 write!(f, "timestamp {:?} not beyond batch lower {:?}", ts, lower)
119 }
120 InvalidUsage::UpdateBeyondUpper { ts, expected_upper } => write!(
121 f,
122 "timestamp {:?} is beyond the expected batch upper: {:?}",
123 ts, expected_upper
124 ),
125 InvalidUsage::BatchNotFromThisShard {
126 batch_shard,
127 handle_shard,
128 } => write!(f, "batch was from {} not {}", batch_shard, handle_shard),
129 InvalidUsage::FinalizationError { since, upper } => {
130 write!(
131 f,
132 "finalized without fully advancing since {since:?} and upper {upper:?}"
133 )
134 }
135 InvalidUsage::CodecMismatch(err) => std::fmt::Display::fmt(err, f),
136 InvalidUsage::InvalidRewrite(err) => write!(f, "invalid rewrite: {err}"),
137 }
138 }
139}
140
141impl<T: Debug> std::error::Error for InvalidUsage<T> {}
142
143#[derive(Debug)]
145#[cfg_attr(any(test, debug_assertions), derive(PartialEq))]
146pub struct CodecMismatch {
147 pub(crate) requested: (String, String, String, String, Option<CodecConcreteType>),
152 pub(crate) actual: (String, String, String, String, Option<CodecConcreteType>),
157}
158
159impl std::error::Error for CodecMismatch {}
160
161impl std::fmt::Display for CodecMismatch {
162 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
163 write!(
164 f,
165 "requested codecs {:?} did not match ones in durable storage {:?}",
166 self.requested, self.actual
167 )
168 }
169}
170
171#[derive(Debug)]
174#[cfg_attr(any(test, debug_assertions), derive(PartialEq))]
175pub struct CodecConcreteType(#[allow(dead_code)] pub(crate) &'static str);
176
177impl<T> From<CodecMismatch> for InvalidUsage<T> {
178 fn from(x: CodecMismatch) -> Self {
179 InvalidUsage::CodecMismatch(Box::new(x))
180 }
181}
182
183impl<T> From<Box<CodecMismatch>> for InvalidUsage<T> {
184 fn from(x: Box<CodecMismatch>) -> Self {
185 InvalidUsage::CodecMismatch(x)
186 }
187}
188
189#[derive(Debug)]
190pub(crate) struct CodecMismatchT {
191 pub(crate) requested: String,
193 pub(crate) actual: String,
195}
196
197impl std::error::Error for CodecMismatchT {}
198
199impl std::fmt::Display for CodecMismatchT {
200 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
201 write!(
202 f,
203 "requested ts codec {:?} did not match one in durable storage {:?}",
204 self.requested, self.actual
205 )
206 }
207}
208
209#[derive(Debug, PartialEq)]
213pub struct UpperMismatch<T> {
214 pub expected: Antichain<T>,
216 pub current: Antichain<T>,
218}
219
220impl<T: Timestamp> std::fmt::Display for UpperMismatch<T> {
221 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
222 write!(
223 f,
224 "expected upper {:?} did not match current upper {:?}",
225 self.expected, self.current,
226 )
227 }
228}