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 InvalidBounds {
24 lower: Antichain<T>,
26 upper: Antichain<T>,
28 },
29 InvalidEmptyTimeInterval {
31 lower: Antichain<T>,
33 upper: Antichain<T>,
35 keys: Vec<String>,
37 },
38 InvalidBatchBounds {
40 batch_lower: Antichain<T>,
42 batch_upper: Antichain<T>,
44 append_lower: Antichain<T>,
46 append_upper: Antichain<T>,
48 },
49 UpdateNotBeyondLower {
51 ts: T,
53 lower: Antichain<T>,
55 },
56 UpdateBeyondUpper {
58 ts: T,
60 expected_upper: Antichain<T>,
62 },
63 BatchNotFromThisShard {
66 batch_shard: ShardId,
68 handle_shard: ShardId,
70 },
71 FinalizationError {
73 since: Antichain<T>,
75 upper: Antichain<T>,
77 },
78 CodecMismatch(Box<CodecMismatch>),
80 InvalidRewrite(String),
82}
83
84impl<T: Debug> std::fmt::Display for InvalidUsage<T> {
85 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
86 match self {
87 InvalidUsage::InvalidBounds { lower, upper } => {
88 write!(f, "invalid bounds [{:?}, {:?})", lower, upper)
89 }
90 InvalidUsage::InvalidEmptyTimeInterval { lower, upper, keys } => {
91 write!(
92 f,
93 "invalid empty time interval [{:?}, {:?} {:?})",
94 lower, upper, keys
95 )
96 }
97 InvalidUsage::InvalidBatchBounds {
98 batch_lower,
99 batch_upper,
100 append_lower,
101 append_upper,
102 } => {
103 write!(
104 f,
105 "invalid batch bounds [{:?}, {:?}) for append call with [{:?}, {:?})",
106 batch_lower, batch_upper, append_lower, append_upper
107 )
108 }
109 InvalidUsage::UpdateNotBeyondLower { ts, lower } => {
110 write!(f, "timestamp {:?} not beyond batch lower {:?}", ts, lower)
111 }
112 InvalidUsage::UpdateBeyondUpper { ts, expected_upper } => write!(
113 f,
114 "timestamp {:?} is beyond the expected batch upper: {:?}",
115 ts, expected_upper
116 ),
117 InvalidUsage::BatchNotFromThisShard {
118 batch_shard,
119 handle_shard,
120 } => write!(f, "batch was from {} not {}", batch_shard, handle_shard),
121 InvalidUsage::FinalizationError { since, upper } => {
122 write!(
123 f,
124 "finalized without fully advancing since {since:?} and upper {upper:?}"
125 )
126 }
127 InvalidUsage::CodecMismatch(err) => std::fmt::Display::fmt(err, f),
128 InvalidUsage::InvalidRewrite(err) => write!(f, "invalid rewrite: {err}"),
129 }
130 }
131}
132
133impl<T: Debug> std::error::Error for InvalidUsage<T> {}
134
135#[derive(Debug)]
137#[cfg_attr(any(test, debug_assertions), derive(PartialEq))]
138pub struct CodecMismatch {
139 pub(crate) requested: (String, String, String, String, Option<CodecConcreteType>),
144 pub(crate) actual: (String, String, String, String, Option<CodecConcreteType>),
149}
150
151impl std::error::Error for CodecMismatch {}
152
153impl std::fmt::Display for CodecMismatch {
154 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
155 write!(
156 f,
157 "requested codecs {:?} did not match ones in durable storage {:?}",
158 self.requested, self.actual
159 )
160 }
161}
162
163#[derive(Debug)]
166#[cfg_attr(any(test, debug_assertions), derive(PartialEq))]
167pub struct CodecConcreteType(#[allow(dead_code)] pub(crate) &'static str);
168
169impl<T> From<CodecMismatch> for InvalidUsage<T> {
170 fn from(x: CodecMismatch) -> Self {
171 InvalidUsage::CodecMismatch(Box::new(x))
172 }
173}
174
175impl<T> From<Box<CodecMismatch>> for InvalidUsage<T> {
176 fn from(x: Box<CodecMismatch>) -> Self {
177 InvalidUsage::CodecMismatch(x)
178 }
179}
180
181#[derive(Debug)]
182pub(crate) struct CodecMismatchT {
183 pub(crate) requested: String,
185 pub(crate) actual: String,
187}
188
189impl std::error::Error for CodecMismatchT {}
190
191impl std::fmt::Display for CodecMismatchT {
192 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
193 write!(
194 f,
195 "requested ts codec {:?} did not match one in durable storage {:?}",
196 self.requested, self.actual
197 )
198 }
199}
200
201#[derive(Debug, PartialEq)]
205pub struct UpperMismatch<T> {
206 pub expected: Antichain<T>,
208 pub current: Antichain<T>,
210}
211
212impl<T: Timestamp> std::fmt::Display for UpperMismatch<T> {
213 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
214 write!(
215 f,
216 "expected upper {:?} did not match current upper {:?}",
217 self.expected, self.current,
218 )
219 }
220}