1use crate::{
2 declaration::DeclarationSnapshotError,
3 key::{StableKey, StableKeyError},
4 physical::CommitRecoveryError,
5 schema::SchemaMetadataError,
6 slot::AllocationSlotDescriptor,
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("stable key '{stable_key}' appears in more than one allocation record")]
45 DuplicateStableKey {
46 stable_key: StableKey,
48 },
49 #[error("allocation slot '{slot:?}' appears in more than one allocation record")]
51 DuplicateSlot {
52 slot: Box<AllocationSlotDescriptor>,
54 },
55 #[error("stable key '{stable_key}' has first_generation after last_seen_generation")]
57 InvalidRecordGenerationOrder {
58 stable_key: StableKey,
60 first_generation: u64,
62 last_seen_generation: u64,
64 },
65 #[error(
67 "stable key '{stable_key}' references generation {generation} after current generation {current_generation}"
68 )]
69 FutureRecordGeneration {
70 stable_key: StableKey,
72 generation: u64,
74 current_generation: u64,
76 },
77 #[error("stable key '{stable_key}' is not retired but has retired_generation metadata")]
79 UnexpectedRetiredGeneration {
80 stable_key: StableKey,
82 },
83 #[error("stable key '{stable_key}' is retired but retired_generation is missing")]
85 MissingRetiredGeneration {
86 stable_key: StableKey,
88 },
89 #[error("stable key '{stable_key}' has retired_generation before first_generation")]
91 RetiredBeforeFirstGeneration {
92 stable_key: StableKey,
94 first_generation: u64,
96 retired_generation: u64,
98 },
99 #[error("stable key '{stable_key}' has empty schema metadata history")]
101 EmptySchemaHistory {
102 stable_key: StableKey,
104 },
105 #[error("stable key '{stable_key}' has non-increasing schema metadata generation history")]
107 NonIncreasingSchemaHistory {
108 stable_key: StableKey,
110 },
111 #[error("stable key '{stable_key}' has schema metadata generation outside the ledger bounds")]
113 SchemaHistoryOutOfBounds {
114 stable_key: StableKey,
116 generation: u64,
118 },
119 #[error("stable key '{stable_key}' has invalid schema metadata at generation {generation}")]
121 InvalidSchemaMetadata {
122 stable_key: StableKey,
124 generation: u64,
126 error: SchemaMetadataError,
128 },
129 #[error("generation {generation} appears more than once")]
131 DuplicateGeneration {
132 generation: u64,
134 },
135 #[error("generation {generation} is after current generation {current_generation}")]
137 FutureGeneration {
138 generation: u64,
140 current_generation: u64,
142 },
143 #[error("generation {generation} has invalid parent generation {parent_generation:?}")]
145 InvalidParentGeneration {
146 generation: u64,
148 parent_generation: Option<u64>,
150 },
151 #[error("current generation {current_generation} has no committed generation record")]
153 MissingCurrentGenerationRecord {
154 current_generation: u64,
156 },
157 #[error("generation records are not strictly increasing at generation {generation}")]
159 NonIncreasingGenerationRecords {
160 generation: u64,
162 },
163 #[error(
165 "generation {generation} does not link to previous committed generation {expected_parent:?}"
166 )]
167 BrokenGenerationChain {
168 generation: u64,
170 expected_parent: Option<u64>,
172 actual_parent: Option<u64>,
174 },
175 #[error("stable key '{stable_key}' references unknown generation {generation}")]
177 UnknownRecordGeneration {
178 stable_key: StableKey,
180 generation: u64,
182 },
183 #[error(transparent)]
185 DiagnosticMetadata(DeclarationSnapshotError),
186}
187
188#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
193pub enum LedgerCommitError<E> {
194 #[error(transparent)]
196 Recovery(CommitRecoveryError),
197 #[error(
199 "physical generation {physical_generation} does not match logical ledger generation {logical_generation}"
200 )]
201 PhysicalLogicalGenerationMismatch {
202 physical_generation: u64,
204 logical_generation: u64,
206 },
207 #[error("allocation ledger codec failed")]
209 Codec(E),
210 #[error(transparent)]
212 Compatibility(LedgerCompatibilityError),
213 #[error(transparent)]
215 Integrity(LedgerIntegrityError),
216}
217
218#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
223pub enum AllocationStageError {
224 #[error(
226 "validated allocations were produced at generation {validated_generation}, but ledger is at generation {ledger_generation}"
227 )]
228 StaleValidatedAllocations {
229 validated_generation: u64,
231 ledger_generation: u64,
233 },
234 #[error("ledger generation {generation} cannot be advanced without overflow")]
236 GenerationOverflow {
237 generation: u64,
239 },
240 #[error("generation contains {count} declarations, exceeding the durable u32 diagnostic limit")]
242 TooManyDeclarations {
243 count: usize,
245 },
246 #[error("stable key '{stable_key}' has invalid schema metadata")]
248 InvalidSchemaMetadata {
249 stable_key: StableKey,
251 error: SchemaMetadataError,
253 },
254 #[error("stable key '{stable_key}' was historically bound to a different allocation slot")]
256 StableKeySlotConflict {
257 stable_key: StableKey,
259 historical_slot: Box<AllocationSlotDescriptor>,
261 declared_slot: Box<AllocationSlotDescriptor>,
263 },
264 #[error("allocation slot '{slot:?}' was historically bound to stable key '{historical_key}'")]
266 SlotStableKeyConflict {
267 slot: Box<AllocationSlotDescriptor>,
269 historical_key: StableKey,
271 declared_key: StableKey,
273 },
274 #[error("stable key '{stable_key}' was explicitly retired and cannot be redeclared")]
276 RetiredAllocation {
277 stable_key: StableKey,
279 slot: Box<AllocationSlotDescriptor>,
281 },
282}
283
284#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
289pub enum AllocationReservationError {
290 #[error("ledger generation {generation} cannot be advanced without overflow")]
292 GenerationOverflow {
293 generation: u64,
295 },
296 #[error("generation contains {count} reservations, exceeding the durable u32 diagnostic limit")]
298 TooManyReservations {
299 count: usize,
301 },
302 #[error("stable key '{stable_key}' has invalid schema metadata")]
304 InvalidSchemaMetadata {
305 stable_key: StableKey,
307 error: SchemaMetadataError,
309 },
310 #[error("stable key '{stable_key}' was historically bound to a different allocation slot")]
312 StableKeySlotConflict {
313 stable_key: StableKey,
315 historical_slot: Box<AllocationSlotDescriptor>,
317 reserved_slot: Box<AllocationSlotDescriptor>,
319 },
320 #[error("allocation slot '{slot:?}' was historically bound to stable key '{historical_key}'")]
322 SlotStableKeyConflict {
323 slot: Box<AllocationSlotDescriptor>,
325 historical_key: StableKey,
327 reserved_key: StableKey,
329 },
330 #[error("stable key '{stable_key}' is already active and cannot be reserved")]
332 ActiveAllocation {
333 stable_key: StableKey,
335 slot: Box<AllocationSlotDescriptor>,
337 },
338 #[error("stable key '{stable_key}' was explicitly retired and cannot be reserved")]
340 RetiredAllocation {
341 stable_key: StableKey,
343 slot: Box<AllocationSlotDescriptor>,
345 },
346}
347
348#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
353pub enum AllocationRetirementError {
354 #[error(transparent)]
356 Key(StableKeyError),
357 #[error("ledger generation {generation} cannot be advanced without overflow")]
359 GenerationOverflow {
360 generation: u64,
362 },
363 #[error("stable key '{0}' has no allocation record to retire")]
365 UnknownStableKey(StableKey),
366 #[error("stable key '{stable_key}' cannot be retired for a different allocation slot")]
368 SlotMismatch {
369 stable_key: StableKey,
371 historical_slot: Box<AllocationSlotDescriptor>,
373 retired_slot: Box<AllocationSlotDescriptor>,
375 },
376 #[error("stable key '{stable_key}' was already retired")]
378 AlreadyRetired {
379 stable_key: StableKey,
381 slot: Box<AllocationSlotDescriptor>,
383 },
384}