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("stable key '{stable_key}' has invalid schema metadata")]
242 InvalidSchemaMetadata {
243 stable_key: StableKey,
245 error: SchemaMetadataError,
247 },
248 #[error("stable key '{stable_key}' was historically bound to a different allocation slot")]
250 StableKeySlotConflict {
251 stable_key: StableKey,
253 historical_slot: Box<AllocationSlotDescriptor>,
255 declared_slot: Box<AllocationSlotDescriptor>,
257 },
258 #[error("allocation slot '{slot:?}' was historically bound to stable key '{historical_key}'")]
260 SlotStableKeyConflict {
261 slot: Box<AllocationSlotDescriptor>,
263 historical_key: StableKey,
265 declared_key: StableKey,
267 },
268 #[error("stable key '{stable_key}' was explicitly retired and cannot be redeclared")]
270 RetiredAllocation {
271 stable_key: StableKey,
273 slot: Box<AllocationSlotDescriptor>,
275 },
276}
277
278#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
283pub enum AllocationReservationError {
284 #[error("ledger generation {generation} cannot be advanced without overflow")]
286 GenerationOverflow {
287 generation: u64,
289 },
290 #[error("stable key '{stable_key}' has invalid schema metadata")]
292 InvalidSchemaMetadata {
293 stable_key: StableKey,
295 error: SchemaMetadataError,
297 },
298 #[error("stable key '{stable_key}' was historically bound to a different allocation slot")]
300 StableKeySlotConflict {
301 stable_key: StableKey,
303 historical_slot: Box<AllocationSlotDescriptor>,
305 reserved_slot: Box<AllocationSlotDescriptor>,
307 },
308 #[error("allocation slot '{slot:?}' was historically bound to stable key '{historical_key}'")]
310 SlotStableKeyConflict {
311 slot: Box<AllocationSlotDescriptor>,
313 historical_key: StableKey,
315 reserved_key: StableKey,
317 },
318 #[error("stable key '{stable_key}' is already active and cannot be reserved")]
320 ActiveAllocation {
321 stable_key: StableKey,
323 slot: Box<AllocationSlotDescriptor>,
325 },
326 #[error("stable key '{stable_key}' was explicitly retired and cannot be reserved")]
328 RetiredAllocation {
329 stable_key: StableKey,
331 slot: Box<AllocationSlotDescriptor>,
333 },
334}
335
336#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
341pub enum AllocationRetirementError {
342 #[error(transparent)]
344 Key(StableKeyError),
345 #[error("ledger generation {generation} cannot be advanced without overflow")]
347 GenerationOverflow {
348 generation: u64,
350 },
351 #[error("stable key '{0}' has no allocation record to retire")]
353 UnknownStableKey(StableKey),
354 #[error("stable key '{stable_key}' cannot be retired for a different allocation slot")]
356 SlotMismatch {
357 stable_key: StableKey,
359 historical_slot: Box<AllocationSlotDescriptor>,
361 retired_slot: Box<AllocationSlotDescriptor>,
363 },
364 #[error("stable key '{stable_key}' was already retired")]
366 AlreadyRetired {
367 stable_key: StableKey,
369 slot: Box<AllocationSlotDescriptor>,
371 },
372}