1use crate::{
2 declaration::DeclarationSnapshotError,
3 key::{StableKey, StableKeyError},
4 ledger::LedgerPayloadEnvelopeError,
5 physical::CommitRecoveryError,
6 schema::SchemaMetadataError,
7 slot::{AllocationSlotDescriptor, MemoryManagerSlotError},
8};
9
10#[non_exhaustive]
17#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
18pub enum LedgerIntegrityError {
19 #[error(transparent)]
21 InvalidStableKey(StableKeyError),
22 #[error(transparent)]
24 InvalidSlotDescriptor(MemoryManagerSlotError),
25 #[error("stable key '{stable_key}' appears in more than one allocation record")]
27 DuplicateStableKey {
28 stable_key: StableKey,
30 },
31 #[error("allocation slot '{slot:?}' appears in more than one allocation record")]
33 DuplicateSlot {
34 slot: Box<AllocationSlotDescriptor>,
36 },
37 #[error("stable key '{stable_key}' has first_generation after last_seen_generation")]
39 InvalidRecordGenerationOrder {
40 stable_key: StableKey,
42 first_generation: u64,
44 last_seen_generation: u64,
46 },
47 #[error(
49 "stable key '{stable_key}' references generation {generation} after current generation {current_generation}"
50 )]
51 FutureRecordGeneration {
52 stable_key: StableKey,
54 generation: u64,
56 current_generation: u64,
58 },
59 #[error("stable key '{stable_key}' was retired before first_generation")]
61 RetiredBeforeFirstGeneration {
62 stable_key: StableKey,
64 first_generation: u64,
66 retired_generation: u64,
68 },
69 #[error("stable key '{stable_key}' was retired at or before last_seen_generation")]
71 RetirementNotAfterLastSeen {
72 stable_key: StableKey,
74 last_seen_generation: u64,
76 retired_generation: u64,
78 },
79 #[error("stable key '{stable_key}' has empty schema metadata history")]
81 EmptySchemaHistory {
82 stable_key: StableKey,
84 },
85 #[error(
87 "stable key '{stable_key}' has schema metadata that does not begin at first_generation"
88 )]
89 SchemaHistoryStartMismatch {
90 stable_key: StableKey,
92 first_generation: u64,
94 schema_generation: u64,
96 },
97 #[error("stable key '{stable_key}' has non-increasing schema metadata generation history")]
99 NonIncreasingSchemaHistory {
100 stable_key: StableKey,
102 },
103 #[error("stable key '{stable_key}' has schema metadata generation outside the ledger bounds")]
105 SchemaHistoryOutOfBounds {
106 stable_key: StableKey,
108 generation: u64,
110 },
111 #[error("stable key '{stable_key}' has schema metadata after last_seen_generation")]
113 SchemaHistoryAfterLastSeen {
114 stable_key: StableKey,
116 generation: u64,
118 last_seen_generation: u64,
120 },
121 #[error("stable key '{stable_key}' has invalid schema metadata at generation {generation}")]
123 InvalidSchemaMetadata {
124 stable_key: StableKey,
126 generation: u64,
128 error: SchemaMetadataError,
130 },
131 #[error("generation {generation} appears more than once")]
133 DuplicateGeneration {
134 generation: u64,
136 },
137 #[error("generation {generation} is after current generation {current_generation}")]
139 FutureGeneration {
140 generation: u64,
142 current_generation: u64,
144 },
145 #[error("generation {generation} has invalid parent generation {parent_generation}")]
147 InvalidParentGeneration {
148 generation: u64,
150 parent_generation: u64,
152 },
153 #[error("current generation {current_generation} has no committed generation record")]
155 MissingCurrentGenerationRecord {
156 current_generation: u64,
158 },
159 #[error("generation records are not strictly increasing at generation {generation}")]
161 NonIncreasingGenerationRecords {
162 generation: u64,
164 },
165 #[error(
167 "generation {generation} does not link to previous committed generation {expected_parent}"
168 )]
169 BrokenGenerationChain {
170 generation: u64,
172 expected_parent: u64,
174 actual_parent: u64,
176 },
177 #[error("stable key '{stable_key}' references unknown generation {generation}")]
179 UnknownRecordGeneration {
180 stable_key: StableKey,
182 generation: u64,
184 },
185 #[error(transparent)]
187 DiagnosticMetadata(DeclarationSnapshotError),
188}
189
190#[non_exhaustive]
195#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
196pub enum LedgerCommitError {
197 #[error(transparent)]
199 Recovery(CommitRecoveryError),
200 #[error(transparent)]
202 PayloadEnvelope(LedgerPayloadEnvelopeError),
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(String),
216 #[error(transparent)]
218 Integrity(LedgerIntegrityError),
219}
220
221#[non_exhaustive]
226#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
227pub enum AllocationStageError {
228 #[error(
230 "validated allocations were produced at generation {validated_generation}, but ledger is at generation {ledger_generation}"
231 )]
232 StaleValidatedAllocations {
233 validated_generation: u64,
235 ledger_generation: u64,
237 },
238 #[error("ledger generation {generation} cannot be advanced without overflow")]
240 GenerationOverflow {
241 generation: u64,
243 },
244 #[error("generation contains {count} declarations, exceeding the durable u32 diagnostic limit")]
246 TooManyDeclarations {
247 count: usize,
249 },
250 #[error("stable key '{stable_key}' has invalid schema metadata")]
252 InvalidSchemaMetadata {
253 stable_key: StableKey,
255 error: SchemaMetadataError,
257 },
258 #[error("stable key '{stable_key}' was historically bound to a different allocation slot")]
260 StableKeySlotConflict {
261 stable_key: StableKey,
263 historical_slot: Box<AllocationSlotDescriptor>,
265 declared_slot: Box<AllocationSlotDescriptor>,
267 },
268 #[error("allocation slot '{slot:?}' was historically bound to stable key '{historical_key}'")]
270 SlotStableKeyConflict {
271 slot: Box<AllocationSlotDescriptor>,
273 historical_key: StableKey,
275 declared_key: StableKey,
277 },
278 #[error("stable key '{stable_key}' was explicitly retired and cannot be redeclared")]
280 RetiredAllocation {
281 stable_key: StableKey,
283 slot: Box<AllocationSlotDescriptor>,
285 },
286 #[error("stable key '{stable_key}' produced an unexpected active-allocation conflict")]
289 UnexpectedActiveAllocationConflict {
290 stable_key: StableKey,
292 slot: Box<AllocationSlotDescriptor>,
294 },
295}
296
297#[non_exhaustive]
302#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
303pub enum AllocationReservationError {
304 #[error("ledger generation {generation} cannot be advanced without overflow")]
306 GenerationOverflow {
307 generation: u64,
309 },
310 #[error("generation contains {count} reservations, exceeding the durable u32 diagnostic limit")]
312 TooManyReservations {
313 count: usize,
315 },
316 #[error("stable key '{stable_key}' has invalid schema metadata")]
318 InvalidSchemaMetadata {
319 stable_key: StableKey,
321 error: SchemaMetadataError,
323 },
324 #[error("reservation declaration is invalid")]
326 InvalidDeclaration(#[source] DeclarationSnapshotError),
327 #[error("stable key '{stable_key}' was historically bound to a different allocation slot")]
329 StableKeySlotConflict {
330 stable_key: StableKey,
332 historical_slot: Box<AllocationSlotDescriptor>,
334 reserved_slot: Box<AllocationSlotDescriptor>,
336 },
337 #[error("allocation slot '{slot:?}' was historically bound to stable key '{historical_key}'")]
339 SlotStableKeyConflict {
340 slot: Box<AllocationSlotDescriptor>,
342 historical_key: StableKey,
344 reserved_key: StableKey,
346 },
347 #[error("stable key '{stable_key}' is already active and cannot be reserved")]
349 ActiveAllocation {
350 stable_key: StableKey,
352 slot: Box<AllocationSlotDescriptor>,
354 },
355 #[error("stable key '{stable_key}' was explicitly retired and cannot be reserved")]
357 RetiredAllocation {
358 stable_key: StableKey,
360 slot: Box<AllocationSlotDescriptor>,
362 },
363}
364
365#[non_exhaustive]
370#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
371pub enum AllocationRetirementError {
372 #[error(transparent)]
374 Key(StableKeyError),
375 #[error(transparent)]
377 MemoryManagerSlot(MemoryManagerSlotError),
378 #[error("ledger generation {generation} cannot be advanced without overflow")]
380 GenerationOverflow {
381 generation: u64,
383 },
384 #[error("stable key '{0}' has no allocation record to retire")]
386 UnknownStableKey(StableKey),
387 #[error("stable key '{stable_key}' cannot be retired for a different allocation slot")]
389 SlotMismatch {
390 stable_key: StableKey,
392 historical_slot: Box<AllocationSlotDescriptor>,
394 retired_slot: Box<AllocationSlotDescriptor>,
396 },
397 #[error("stable key '{stable_key}' was already retired")]
399 AlreadyRetired {
400 stable_key: StableKey,
402 slot: Box<AllocationSlotDescriptor>,
404 },
405}