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("ledger exceeds {resource} limit {limit}")]
21 LimitExceeded {
22 resource: &'static str,
23 limit: usize,
24 },
25 #[error(transparent)]
27 InvalidStableKey(StableKeyError),
28 #[error(transparent)]
30 InvalidSlotDescriptor(MemoryManagerSlotError),
31 #[error("stable key '{stable_key}' appears in more than one allocation record")]
33 DuplicateStableKey {
34 stable_key: StableKey,
36 },
37 #[error("allocation slot '{slot:?}' appears in more than one allocation record")]
39 DuplicateSlot {
40 slot: Box<AllocationSlotDescriptor>,
42 },
43 #[error("stable key '{stable_key}' has first_generation after last_seen_generation")]
45 InvalidRecordGenerationOrder {
46 stable_key: StableKey,
48 first_generation: u64,
50 last_seen_generation: u64,
52 },
53 #[error(
55 "stable key '{stable_key}' references generation {generation} after current generation {current_generation}"
56 )]
57 FutureRecordGeneration {
58 stable_key: StableKey,
60 generation: u64,
62 current_generation: u64,
64 },
65 #[error("stable key '{stable_key}' was retired before first_generation")]
67 RetiredBeforeFirstGeneration {
68 stable_key: StableKey,
70 first_generation: u64,
72 retired_generation: u64,
74 },
75 #[error("stable key '{stable_key}' was retired at or before last_seen_generation")]
77 RetirementNotAfterLastSeen {
78 stable_key: StableKey,
80 last_seen_generation: u64,
82 retired_generation: u64,
84 },
85 #[error("stable key '{stable_key}' has empty schema metadata history")]
87 EmptySchemaHistory {
88 stable_key: StableKey,
90 },
91 #[error(
93 "stable key '{stable_key}' has schema metadata that does not begin at first_generation"
94 )]
95 SchemaHistoryStartMismatch {
96 stable_key: StableKey,
98 first_generation: u64,
100 schema_generation: u64,
102 },
103 #[error("stable key '{stable_key}' has non-increasing schema metadata generation history")]
105 NonIncreasingSchemaHistory {
106 stable_key: StableKey,
108 },
109 #[error("stable key '{stable_key}' has schema metadata generation outside the ledger bounds")]
111 SchemaHistoryOutOfBounds {
112 stable_key: StableKey,
114 generation: u64,
116 },
117 #[error("stable key '{stable_key}' has schema metadata after last_seen_generation")]
119 SchemaHistoryAfterLastSeen {
120 stable_key: StableKey,
122 generation: u64,
124 last_seen_generation: u64,
126 },
127 #[error("stable key '{stable_key}' has invalid schema metadata at generation {generation}")]
129 InvalidSchemaMetadata {
130 stable_key: StableKey,
132 generation: u64,
134 error: SchemaMetadataError,
136 },
137 #[error("generation {generation} appears more than once")]
139 DuplicateGeneration {
140 generation: u64,
142 },
143 #[error("generation {generation} is after current generation {current_generation}")]
145 FutureGeneration {
146 generation: u64,
148 current_generation: u64,
150 },
151 #[error("generation {generation} has invalid parent generation {parent_generation}")]
153 InvalidParentGeneration {
154 generation: u64,
156 parent_generation: u64,
158 },
159 #[error("current generation {current_generation} has no committed generation record")]
161 MissingCurrentGenerationRecord {
162 current_generation: u64,
164 },
165 #[error("generation records are not strictly increasing at generation {generation}")]
167 NonIncreasingGenerationRecords {
168 generation: u64,
170 },
171 #[error(
173 "generation {generation} does not link to previous committed generation {expected_parent}"
174 )]
175 BrokenGenerationChain {
176 generation: u64,
178 expected_parent: u64,
180 actual_parent: u64,
182 },
183 #[error("stable key '{stable_key}' references unknown generation {generation}")]
185 UnknownRecordGeneration {
186 stable_key: StableKey,
188 generation: u64,
190 },
191 #[error(transparent)]
193 DiagnosticMetadata(DeclarationSnapshotError),
194}
195
196#[non_exhaustive]
201#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
202pub enum LedgerCommitError {
203 #[error(transparent)]
205 Recovery(CommitRecoveryError),
206 #[error(transparent)]
208 PayloadEnvelope(LedgerPayloadEnvelopeError),
209 #[error(
211 "physical generation {physical_generation} does not match logical ledger generation {logical_generation}"
212 )]
213 PhysicalLogicalGenerationMismatch {
214 physical_generation: u64,
216 logical_generation: u64,
218 },
219 #[error("allocation ledger codec failed")]
221 Codec(String),
222 #[error(transparent)]
224 Integrity(LedgerIntegrityError),
225}
226
227#[non_exhaustive]
232#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
233pub enum AllocationStageError {
234 #[error(transparent)]
235 Integrity(#[from] LedgerIntegrityError),
236 #[error(
238 "validated allocations were produced at generation {validated_generation}, but ledger is at generation {ledger_generation}"
239 )]
240 StaleValidatedAllocations {
241 validated_generation: u64,
243 ledger_generation: u64,
245 },
246 #[error("ledger generation {generation} cannot be advanced without overflow")]
248 GenerationOverflow {
249 generation: u64,
251 },
252 #[error("generation contains {count} declarations, exceeding the durable u32 diagnostic limit")]
254 TooManyDeclarations {
255 count: usize,
257 },
258 #[error("stable key '{stable_key}' has invalid schema metadata")]
260 InvalidSchemaMetadata {
261 stable_key: StableKey,
263 error: SchemaMetadataError,
265 },
266 #[error("stable key '{stable_key}' was historically bound to a different allocation slot")]
268 StableKeySlotConflict {
269 stable_key: StableKey,
271 historical_slot: Box<AllocationSlotDescriptor>,
273 declared_slot: Box<AllocationSlotDescriptor>,
275 },
276 #[error("allocation slot '{slot:?}' was historically bound to stable key '{historical_key}'")]
278 SlotStableKeyConflict {
279 slot: Box<AllocationSlotDescriptor>,
281 historical_key: StableKey,
283 declared_key: StableKey,
285 },
286 #[error("stable key '{stable_key}' was explicitly retired and cannot be redeclared")]
288 RetiredAllocation {
289 stable_key: StableKey,
291 slot: Box<AllocationSlotDescriptor>,
293 },
294 #[error("stable key '{stable_key}' produced an unexpected active-allocation conflict")]
297 UnexpectedActiveAllocationConflict {
298 stable_key: StableKey,
300 slot: Box<AllocationSlotDescriptor>,
302 },
303}
304
305#[non_exhaustive]
310#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
311pub enum AllocationReservationError {
312 #[error(transparent)]
313 Integrity(#[from] LedgerIntegrityError),
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)]
383 Integrity(#[from] LedgerIntegrityError),
384 #[error(transparent)]
386 Key(StableKeyError),
387 #[error(transparent)]
389 MemoryManagerSlot(MemoryManagerSlotError),
390 #[error("ledger generation {generation} cannot be advanced without overflow")]
392 GenerationOverflow {
393 generation: u64,
395 },
396 #[error("stable key '{0}' has no allocation record to retire")]
398 UnknownStableKey(StableKey),
399 #[error("stable key '{stable_key}' cannot be retired for a different allocation slot")]
401 SlotMismatch {
402 stable_key: StableKey,
404 historical_slot: Box<AllocationSlotDescriptor>,
406 retired_slot: Box<AllocationSlotDescriptor>,
408 },
409 #[error("stable key '{stable_key}' was already retired")]
411 AlreadyRetired {
412 stable_key: StableKey,
414 slot: Box<AllocationSlotDescriptor>,
416 },
417}