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]
15#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
16pub enum LedgerIntegrityError {
17 #[error(transparent)]
19 InvalidStableKey(StableKeyError),
20 #[error(transparent)]
22 InvalidSlotDescriptor(MemoryManagerSlotError),
23 #[error("stable key '{stable_key}' appears in more than one allocation record")]
25 DuplicateStableKey {
26 stable_key: StableKey,
28 },
29 #[error("allocation slot '{slot:?}' appears in more than one allocation record")]
31 DuplicateSlot {
32 slot: Box<AllocationSlotDescriptor>,
34 },
35 #[error("stable key '{stable_key}' has first_generation after last_seen_generation")]
37 InvalidRecordGenerationOrder {
38 stable_key: StableKey,
40 first_generation: u64,
42 last_seen_generation: u64,
44 },
45 #[error(
47 "stable key '{stable_key}' references generation {generation} after current generation {current_generation}"
48 )]
49 FutureRecordGeneration {
50 stable_key: StableKey,
52 generation: u64,
54 current_generation: u64,
56 },
57 #[error("stable key '{stable_key}' is not retired but has retired_generation metadata")]
59 UnexpectedRetiredGeneration {
60 stable_key: StableKey,
62 },
63 #[error("stable key '{stable_key}' is retired but retired_generation is missing")]
65 MissingRetiredGeneration {
66 stable_key: StableKey,
68 },
69 #[error("stable key '{stable_key}' has retired_generation before first_generation")]
71 RetiredBeforeFirstGeneration {
72 stable_key: StableKey,
74 first_generation: u64,
76 retired_generation: u64,
78 },
79 #[error("stable key '{stable_key}' has retired_generation at or before last_seen_generation")]
81 RetirementNotAfterLastSeen {
82 stable_key: StableKey,
84 last_seen_generation: u64,
86 retired_generation: u64,
88 },
89 #[error("stable key '{stable_key}' has empty schema metadata history")]
91 EmptySchemaHistory {
92 stable_key: StableKey,
94 },
95 #[error(
97 "stable key '{stable_key}' has schema metadata that does not begin at first_generation"
98 )]
99 SchemaHistoryStartMismatch {
100 stable_key: StableKey,
102 first_generation: u64,
104 schema_generation: u64,
106 },
107 #[error("stable key '{stable_key}' has non-increasing schema metadata generation history")]
109 NonIncreasingSchemaHistory {
110 stable_key: StableKey,
112 },
113 #[error("stable key '{stable_key}' has schema metadata generation outside the ledger bounds")]
115 SchemaHistoryOutOfBounds {
116 stable_key: StableKey,
118 generation: u64,
120 },
121 #[error("stable key '{stable_key}' has schema metadata after last_seen_generation")]
123 SchemaHistoryAfterLastSeen {
124 stable_key: StableKey,
126 generation: u64,
128 last_seen_generation: u64,
130 },
131 #[error("stable key '{stable_key}' has invalid schema metadata at generation {generation}")]
133 InvalidSchemaMetadata {
134 stable_key: StableKey,
136 generation: u64,
138 error: SchemaMetadataError,
140 },
141 #[error("generation {generation} appears more than once")]
143 DuplicateGeneration {
144 generation: u64,
146 },
147 #[error("generation {generation} is after current generation {current_generation}")]
149 FutureGeneration {
150 generation: u64,
152 current_generation: u64,
154 },
155 #[error("generation {generation} has invalid parent generation {parent_generation}")]
157 InvalidParentGeneration {
158 generation: u64,
160 parent_generation: u64,
162 },
163 #[error("current generation {current_generation} has no committed generation record")]
165 MissingCurrentGenerationRecord {
166 current_generation: u64,
168 },
169 #[error("generation records are not strictly increasing at generation {generation}")]
171 NonIncreasingGenerationRecords {
172 generation: u64,
174 },
175 #[error(
177 "generation {generation} does not link to previous committed generation {expected_parent}"
178 )]
179 BrokenGenerationChain {
180 generation: u64,
182 expected_parent: u64,
184 actual_parent: u64,
186 },
187 #[error("stable key '{stable_key}' references unknown generation {generation}")]
189 UnknownRecordGeneration {
190 stable_key: StableKey,
192 generation: u64,
194 },
195 #[error(transparent)]
197 DiagnosticMetadata(DeclarationSnapshotError),
198}
199
200#[non_exhaustive]
205#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
206pub enum LedgerCommitError {
207 #[error(transparent)]
209 Recovery(CommitRecoveryError),
210 #[error(transparent)]
212 PayloadEnvelope(LedgerPayloadEnvelopeError),
213 #[error(
215 "physical generation {physical_generation} does not match logical ledger generation {logical_generation}"
216 )]
217 PhysicalLogicalGenerationMismatch {
218 physical_generation: u64,
220 logical_generation: u64,
222 },
223 #[error("allocation ledger codec failed")]
225 Codec(String),
226 #[error(transparent)]
228 Integrity(LedgerIntegrityError),
229}
230
231#[non_exhaustive]
236#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
237pub enum AllocationStageError {
238 #[error(
240 "validated allocations were produced at generation {validated_generation}, but ledger is at generation {ledger_generation}"
241 )]
242 StaleValidatedAllocations {
243 validated_generation: u64,
245 ledger_generation: u64,
247 },
248 #[error("ledger generation {generation} cannot be advanced without overflow")]
250 GenerationOverflow {
251 generation: u64,
253 },
254 #[error("generation contains {count} declarations, exceeding the durable u32 diagnostic limit")]
256 TooManyDeclarations {
257 count: usize,
259 },
260 #[error("stable key '{stable_key}' has invalid schema metadata")]
262 InvalidSchemaMetadata {
263 stable_key: StableKey,
265 error: SchemaMetadataError,
267 },
268 #[error("stable key '{stable_key}' was historically bound to a different allocation slot")]
270 StableKeySlotConflict {
271 stable_key: StableKey,
273 historical_slot: Box<AllocationSlotDescriptor>,
275 declared_slot: Box<AllocationSlotDescriptor>,
277 },
278 #[error("allocation slot '{slot:?}' was historically bound to stable key '{historical_key}'")]
280 SlotStableKeyConflict {
281 slot: Box<AllocationSlotDescriptor>,
283 historical_key: StableKey,
285 declared_key: StableKey,
287 },
288 #[error("stable key '{stable_key}' was explicitly retired and cannot be redeclared")]
290 RetiredAllocation {
291 stable_key: StableKey,
293 slot: Box<AllocationSlotDescriptor>,
295 },
296 #[error("stable key '{stable_key}' produced an unexpected active-allocation conflict")]
299 UnexpectedActiveAllocationConflict {
300 stable_key: StableKey,
302 slot: Box<AllocationSlotDescriptor>,
304 },
305}
306
307#[non_exhaustive]
312#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
313pub enum AllocationReservationError {
314 #[error("ledger generation {generation} cannot be advanced without overflow")]
316 GenerationOverflow {
317 generation: u64,
319 },
320 #[error("generation contains {count} reservations, exceeding the durable u32 diagnostic limit")]
322 TooManyReservations {
323 count: usize,
325 },
326 #[error("stable key '{stable_key}' has invalid schema metadata")]
328 InvalidSchemaMetadata {
329 stable_key: StableKey,
331 error: SchemaMetadataError,
333 },
334 #[error("reservation declaration is invalid")]
336 InvalidDeclaration(#[source] DeclarationSnapshotError),
337 #[error("stable key '{stable_key}' was historically bound to a different allocation slot")]
339 StableKeySlotConflict {
340 stable_key: StableKey,
342 historical_slot: Box<AllocationSlotDescriptor>,
344 reserved_slot: Box<AllocationSlotDescriptor>,
346 },
347 #[error("allocation slot '{slot:?}' was historically bound to stable key '{historical_key}'")]
349 SlotStableKeyConflict {
350 slot: Box<AllocationSlotDescriptor>,
352 historical_key: StableKey,
354 reserved_key: StableKey,
356 },
357 #[error("stable key '{stable_key}' is already active and cannot be reserved")]
359 ActiveAllocation {
360 stable_key: StableKey,
362 slot: Box<AllocationSlotDescriptor>,
364 },
365 #[error("stable key '{stable_key}' was explicitly retired and cannot be reserved")]
367 RetiredAllocation {
368 stable_key: StableKey,
370 slot: Box<AllocationSlotDescriptor>,
372 },
373}
374
375#[non_exhaustive]
380#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
381pub enum AllocationRetirementError {
382 #[error(transparent)]
384 Key(StableKeyError),
385 #[error(transparent)]
387 MemoryManagerSlot(MemoryManagerSlotError),
388 #[error("ledger generation {generation} cannot be advanced without overflow")]
390 GenerationOverflow {
391 generation: u64,
393 },
394 #[error("stable key '{0}' has no allocation record to retire")]
396 UnknownStableKey(StableKey),
397 #[error("stable key '{stable_key}' cannot be retired for a different allocation slot")]
399 SlotMismatch {
400 stable_key: StableKey,
402 historical_slot: Box<AllocationSlotDescriptor>,
404 retired_slot: Box<AllocationSlotDescriptor>,
406 },
407 #[error("stable key '{stable_key}' was already retired")]
409 AlreadyRetired {
410 stable_key: StableKey,
412 slot: Box<AllocationSlotDescriptor>,
414 },
415}