1use crate::{
2 declaration::DeclarationSnapshotError,
3 key::{StableKey, StableKeyError},
4 physical::CommitRecoveryError,
5 schema::SchemaMetadataError,
6 slot::{AllocationSlotDescriptor, AllocationSlotDescriptorError},
7};
8
9#[derive(Clone, Copy, Debug, Eq, thiserror::Error, PartialEq)]
14pub enum LedgerCompatibilityError {
15 #[error(
17 "ledger_schema_version {found} is unsupported; supported range is {min_supported}-{max_supported}"
18 )]
19 UnsupportedLedgerSchemaVersion {
20 found: u32,
22 min_supported: u32,
24 max_supported: u32,
26 },
27 #[error("physical_format_id {found} is unsupported; supported format is {supported}")]
29 UnsupportedPhysicalFormat {
30 found: u32,
32 supported: u32,
34 },
35}
36
37#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
42pub enum LedgerIntegrityError {
43 #[error(transparent)]
45 InvalidStableKey(StableKeyError),
46 #[error(transparent)]
48 InvalidSlotDescriptor(AllocationSlotDescriptorError),
49 #[error("stable key '{stable_key}' appears in more than one allocation record")]
51 DuplicateStableKey {
52 stable_key: StableKey,
54 },
55 #[error("allocation slot '{slot:?}' appears in more than one allocation record")]
57 DuplicateSlot {
58 slot: Box<AllocationSlotDescriptor>,
60 },
61 #[error("stable key '{stable_key}' has first_generation after last_seen_generation")]
63 InvalidRecordGenerationOrder {
64 stable_key: StableKey,
66 first_generation: u64,
68 last_seen_generation: u64,
70 },
71 #[error(
73 "stable key '{stable_key}' references generation {generation} after current generation {current_generation}"
74 )]
75 FutureRecordGeneration {
76 stable_key: StableKey,
78 generation: u64,
80 current_generation: u64,
82 },
83 #[error("stable key '{stable_key}' is not retired but has retired_generation metadata")]
85 UnexpectedRetiredGeneration {
86 stable_key: StableKey,
88 },
89 #[error("stable key '{stable_key}' is retired but retired_generation is missing")]
91 MissingRetiredGeneration {
92 stable_key: StableKey,
94 },
95 #[error("stable key '{stable_key}' has retired_generation before first_generation")]
97 RetiredBeforeFirstGeneration {
98 stable_key: StableKey,
100 first_generation: u64,
102 retired_generation: u64,
104 },
105 #[error("stable key '{stable_key}' has empty schema metadata history")]
107 EmptySchemaHistory {
108 stable_key: StableKey,
110 },
111 #[error("stable key '{stable_key}' has non-increasing schema metadata generation history")]
113 NonIncreasingSchemaHistory {
114 stable_key: StableKey,
116 },
117 #[error("stable key '{stable_key}' has schema metadata generation outside the ledger bounds")]
119 SchemaHistoryOutOfBounds {
120 stable_key: StableKey,
122 generation: u64,
124 },
125 #[error("stable key '{stable_key}' has invalid schema metadata at generation {generation}")]
127 InvalidSchemaMetadata {
128 stable_key: StableKey,
130 generation: u64,
132 error: SchemaMetadataError,
134 },
135 #[error("generation {generation} appears more than once")]
137 DuplicateGeneration {
138 generation: u64,
140 },
141 #[error("generation {generation} is after current generation {current_generation}")]
143 FutureGeneration {
144 generation: u64,
146 current_generation: u64,
148 },
149 #[error("generation {generation} has invalid parent generation {parent_generation:?}")]
151 InvalidParentGeneration {
152 generation: u64,
154 parent_generation: Option<u64>,
156 },
157 #[error("current generation {current_generation} has no committed generation record")]
159 MissingCurrentGenerationRecord {
160 current_generation: u64,
162 },
163 #[error("generation records are not strictly increasing at generation {generation}")]
165 NonIncreasingGenerationRecords {
166 generation: u64,
168 },
169 #[error(
171 "generation {generation} does not link to previous committed generation {expected_parent:?}"
172 )]
173 BrokenGenerationChain {
174 generation: u64,
176 expected_parent: Option<u64>,
178 actual_parent: Option<u64>,
180 },
181 #[error("stable key '{stable_key}' references unknown generation {generation}")]
183 UnknownRecordGeneration {
184 stable_key: StableKey,
186 generation: u64,
188 },
189 #[error(transparent)]
191 DiagnosticMetadata(DeclarationSnapshotError),
192}
193
194#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
199pub enum LedgerCommitError<E> {
200 #[error(transparent)]
202 Recovery(CommitRecoveryError),
203 #[error(
205 "physical generation {physical_generation} does not match logical ledger generation {logical_generation}"
206 )]
207 PhysicalLogicalGenerationMismatch {
208 physical_generation: u64,
210 logical_generation: u64,
212 },
213 #[error("allocation ledger codec failed")]
215 Codec(E),
216 #[error(transparent)]
218 Compatibility(LedgerCompatibilityError),
219 #[error(transparent)]
221 Integrity(LedgerIntegrityError),
222}
223
224#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
229pub enum AllocationStageError {
230 #[error(
232 "validated allocations were produced at generation {validated_generation}, but ledger is at generation {ledger_generation}"
233 )]
234 StaleValidatedAllocations {
235 validated_generation: u64,
237 ledger_generation: u64,
239 },
240 #[error("ledger generation {generation} cannot be advanced without overflow")]
242 GenerationOverflow {
243 generation: u64,
245 },
246 #[error("generation contains {count} declarations, exceeding the durable u32 diagnostic limit")]
248 TooManyDeclarations {
249 count: usize,
251 },
252 #[error("stable key '{stable_key}' has invalid schema metadata")]
254 InvalidSchemaMetadata {
255 stable_key: StableKey,
257 error: SchemaMetadataError,
259 },
260 #[error("stable key '{stable_key}' was historically bound to a different allocation slot")]
262 StableKeySlotConflict {
263 stable_key: StableKey,
265 historical_slot: Box<AllocationSlotDescriptor>,
267 declared_slot: Box<AllocationSlotDescriptor>,
269 },
270 #[error("allocation slot '{slot:?}' was historically bound to stable key '{historical_key}'")]
272 SlotStableKeyConflict {
273 slot: Box<AllocationSlotDescriptor>,
275 historical_key: StableKey,
277 declared_key: StableKey,
279 },
280 #[error("stable key '{stable_key}' was explicitly retired and cannot be redeclared")]
282 RetiredAllocation {
283 stable_key: StableKey,
285 slot: Box<AllocationSlotDescriptor>,
287 },
288}
289
290#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
295pub enum AllocationReservationError {
296 #[error("ledger generation {generation} cannot be advanced without overflow")]
298 GenerationOverflow {
299 generation: u64,
301 },
302 #[error("generation contains {count} reservations, exceeding the durable u32 diagnostic limit")]
304 TooManyReservations {
305 count: usize,
307 },
308 #[error("stable key '{stable_key}' has invalid schema metadata")]
310 InvalidSchemaMetadata {
311 stable_key: StableKey,
313 error: SchemaMetadataError,
315 },
316 #[error("stable key '{stable_key}' was historically bound to a different allocation slot")]
318 StableKeySlotConflict {
319 stable_key: StableKey,
321 historical_slot: Box<AllocationSlotDescriptor>,
323 reserved_slot: Box<AllocationSlotDescriptor>,
325 },
326 #[error("allocation slot '{slot:?}' was historically bound to stable key '{historical_key}'")]
328 SlotStableKeyConflict {
329 slot: Box<AllocationSlotDescriptor>,
331 historical_key: StableKey,
333 reserved_key: StableKey,
335 },
336 #[error("stable key '{stable_key}' is already active and cannot be reserved")]
338 ActiveAllocation {
339 stable_key: StableKey,
341 slot: Box<AllocationSlotDescriptor>,
343 },
344 #[error("stable key '{stable_key}' was explicitly retired and cannot be reserved")]
346 RetiredAllocation {
347 stable_key: StableKey,
349 slot: Box<AllocationSlotDescriptor>,
351 },
352}
353
354#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
359pub enum AllocationRetirementError {
360 #[error(transparent)]
362 Key(StableKeyError),
363 #[error("ledger generation {generation} cannot be advanced without overflow")]
365 GenerationOverflow {
366 generation: u64,
368 },
369 #[error("stable key '{0}' has no allocation record to retire")]
371 UnknownStableKey(StableKey),
372 #[error("stable key '{stable_key}' cannot be retired for a different allocation slot")]
374 SlotMismatch {
375 stable_key: StableKey,
377 historical_slot: Box<AllocationSlotDescriptor>,
379 retired_slot: Box<AllocationSlotDescriptor>,
381 },
382 #[error("stable key '{stable_key}' was already retired")]
384 AlreadyRetired {
385 stable_key: StableKey,
387 slot: Box<AllocationSlotDescriptor>,
389 },
390}