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 empty schema metadata history")]
81 EmptySchemaHistory {
82 stable_key: StableKey,
84 },
85 #[error("stable key '{stable_key}' has non-increasing schema metadata generation history")]
87 NonIncreasingSchemaHistory {
88 stable_key: StableKey,
90 },
91 #[error("stable key '{stable_key}' has schema metadata generation outside the ledger bounds")]
93 SchemaHistoryOutOfBounds {
94 stable_key: StableKey,
96 generation: u64,
98 },
99 #[error("stable key '{stable_key}' has invalid schema metadata at generation {generation}")]
101 InvalidSchemaMetadata {
102 stable_key: StableKey,
104 generation: u64,
106 error: SchemaMetadataError,
108 },
109 #[error("generation {generation} appears more than once")]
111 DuplicateGeneration {
112 generation: u64,
114 },
115 #[error("generation {generation} is after current generation {current_generation}")]
117 FutureGeneration {
118 generation: u64,
120 current_generation: u64,
122 },
123 #[error("generation {generation} has invalid parent generation {parent_generation}")]
125 InvalidParentGeneration {
126 generation: u64,
128 parent_generation: u64,
130 },
131 #[error("current generation {current_generation} has no committed generation record")]
133 MissingCurrentGenerationRecord {
134 current_generation: u64,
136 },
137 #[error("generation records are not strictly increasing at generation {generation}")]
139 NonIncreasingGenerationRecords {
140 generation: u64,
142 },
143 #[error(
145 "generation {generation} does not link to previous committed generation {expected_parent}"
146 )]
147 BrokenGenerationChain {
148 generation: u64,
150 expected_parent: u64,
152 actual_parent: u64,
154 },
155 #[error("stable key '{stable_key}' references unknown generation {generation}")]
157 UnknownRecordGeneration {
158 stable_key: StableKey,
160 generation: u64,
162 },
163 #[error(transparent)]
165 DiagnosticMetadata(DeclarationSnapshotError),
166}
167
168#[non_exhaustive]
173#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
174pub enum LedgerCommitError {
175 #[error(transparent)]
177 Recovery(CommitRecoveryError),
178 #[error(transparent)]
180 PayloadEnvelope(LedgerPayloadEnvelopeError),
181 #[error(
183 "physical generation {physical_generation} does not match logical ledger generation {logical_generation}"
184 )]
185 PhysicalLogicalGenerationMismatch {
186 physical_generation: u64,
188 logical_generation: u64,
190 },
191 #[error("allocation ledger codec failed")]
193 Codec(String),
194 #[error(transparent)]
196 Integrity(LedgerIntegrityError),
197}
198
199#[non_exhaustive]
204#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
205pub enum AllocationStageError {
206 #[error(
208 "validated allocations were produced at generation {validated_generation}, but ledger is at generation {ledger_generation}"
209 )]
210 StaleValidatedAllocations {
211 validated_generation: u64,
213 ledger_generation: u64,
215 },
216 #[error("ledger generation {generation} cannot be advanced without overflow")]
218 GenerationOverflow {
219 generation: u64,
221 },
222 #[error("generation contains {count} declarations, exceeding the durable u32 diagnostic limit")]
224 TooManyDeclarations {
225 count: usize,
227 },
228 #[error("stable key '{stable_key}' has invalid schema metadata")]
230 InvalidSchemaMetadata {
231 stable_key: StableKey,
233 error: SchemaMetadataError,
235 },
236 #[error("stable key '{stable_key}' was historically bound to a different allocation slot")]
238 StableKeySlotConflict {
239 stable_key: StableKey,
241 historical_slot: Box<AllocationSlotDescriptor>,
243 declared_slot: Box<AllocationSlotDescriptor>,
245 },
246 #[error("allocation slot '{slot:?}' was historically bound to stable key '{historical_key}'")]
248 SlotStableKeyConflict {
249 slot: Box<AllocationSlotDescriptor>,
251 historical_key: StableKey,
253 declared_key: StableKey,
255 },
256 #[error("stable key '{stable_key}' was explicitly retired and cannot be redeclared")]
258 RetiredAllocation {
259 stable_key: StableKey,
261 slot: Box<AllocationSlotDescriptor>,
263 },
264 #[error("stable key '{stable_key}' produced an unexpected active-allocation conflict")]
267 UnexpectedActiveAllocationConflict {
268 stable_key: StableKey,
270 slot: Box<AllocationSlotDescriptor>,
272 },
273}
274
275#[non_exhaustive]
280#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
281pub enum AllocationReservationError {
282 #[error("ledger generation {generation} cannot be advanced without overflow")]
284 GenerationOverflow {
285 generation: u64,
287 },
288 #[error("generation contains {count} reservations, exceeding the durable u32 diagnostic limit")]
290 TooManyReservations {
291 count: usize,
293 },
294 #[error("stable key '{stable_key}' has invalid schema metadata")]
296 InvalidSchemaMetadata {
297 stable_key: StableKey,
299 error: SchemaMetadataError,
301 },
302 #[error("reservation declaration is invalid")]
304 InvalidDeclaration(#[source] DeclarationSnapshotError),
305 #[error("stable key '{stable_key}' was historically bound to a different allocation slot")]
307 StableKeySlotConflict {
308 stable_key: StableKey,
310 historical_slot: Box<AllocationSlotDescriptor>,
312 reserved_slot: Box<AllocationSlotDescriptor>,
314 },
315 #[error("allocation slot '{slot:?}' was historically bound to stable key '{historical_key}'")]
317 SlotStableKeyConflict {
318 slot: Box<AllocationSlotDescriptor>,
320 historical_key: StableKey,
322 reserved_key: StableKey,
324 },
325 #[error("stable key '{stable_key}' is already active and cannot be reserved")]
327 ActiveAllocation {
328 stable_key: StableKey,
330 slot: Box<AllocationSlotDescriptor>,
332 },
333 #[error("stable key '{stable_key}' was explicitly retired and cannot be reserved")]
335 RetiredAllocation {
336 stable_key: StableKey,
338 slot: Box<AllocationSlotDescriptor>,
340 },
341}
342
343#[non_exhaustive]
348#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
349pub enum AllocationRetirementError {
350 #[error(transparent)]
352 Key(StableKeyError),
353 #[error("ledger generation {generation} cannot be advanced without overflow")]
355 GenerationOverflow {
356 generation: u64,
358 },
359 #[error("stable key '{0}' has no allocation record to retire")]
361 UnknownStableKey(StableKey),
362 #[error("stable key '{stable_key}' cannot be retired for a different allocation slot")]
364 SlotMismatch {
365 stable_key: StableKey,
367 historical_slot: Box<AllocationSlotDescriptor>,
369 retired_slot: Box<AllocationSlotDescriptor>,
371 },
372 #[error("stable key '{stable_key}' was already retired")]
374 AlreadyRetired {
375 stable_key: StableKey,
377 slot: Box<AllocationSlotDescriptor>,
379 },
380}