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: {0}")]
221 Codec(String),
222 #[error(transparent)]
224 Integrity(LedgerIntegrityError),
225}
226
227#[non_exhaustive]
234#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
235pub enum AllocationStageError {
236 #[error(transparent)]
237 Integrity(#[from] LedgerIntegrityError),
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("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#[non_exhaustive]
283#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
284pub enum AllocationReservationError {
285 #[error(transparent)]
286 Integrity(#[from] LedgerIntegrityError),
287 #[error("ledger generation {generation} cannot be advanced without overflow")]
289 GenerationOverflow {
290 generation: u64,
292 },
293 #[error("generation contains {count} reservations, exceeding the 255-allocation limit")]
295 TooManyReservations {
296 count: usize,
298 },
299 #[error("stable key '{stable_key}' has invalid schema metadata")]
301 InvalidSchemaMetadata {
302 stable_key: StableKey,
304 error: SchemaMetadataError,
306 },
307 #[error("reservation declaration is invalid")]
309 InvalidDeclaration(#[source] DeclarationSnapshotError),
310 #[error("stable key '{stable_key}' was historically bound to a different allocation slot")]
312 StableKeySlotConflict {
313 stable_key: StableKey,
315 historical_slot: Box<AllocationSlotDescriptor>,
317 reserved_slot: Box<AllocationSlotDescriptor>,
319 },
320 #[error("allocation slot '{slot:?}' was historically bound to stable key '{historical_key}'")]
322 SlotStableKeyConflict {
323 slot: Box<AllocationSlotDescriptor>,
325 historical_key: StableKey,
327 reserved_key: StableKey,
329 },
330 #[error("stable key '{stable_key}' is already active and cannot be reserved")]
332 ActiveAllocation {
333 stable_key: StableKey,
335 slot: Box<AllocationSlotDescriptor>,
337 },
338 #[error("stable key '{stable_key}' was explicitly retired and cannot be reserved")]
340 RetiredAllocation {
341 stable_key: StableKey,
343 slot: Box<AllocationSlotDescriptor>,
345 },
346}
347
348#[non_exhaustive]
353#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
354pub enum AllocationRetirementError {
355 #[error(transparent)]
356 Integrity(#[from] LedgerIntegrityError),
357 #[error(transparent)]
359 Key(StableKeyError),
360 #[error(transparent)]
362 MemoryManagerSlot(MemoryManagerSlotError),
363 #[error("ledger generation {generation} cannot be advanced without overflow")]
365 GenerationOverflow {
366 generation: u64,
368 },
369 #[error("stable key '{0}' has no allocation record to retire")]
371 UnknownStableKey(StableKey),
372 #[error("stable key '{stable_key}' cannot be retired for a different allocation slot")]
374 SlotMismatch {
375 stable_key: StableKey,
377 historical_slot: Box<AllocationSlotDescriptor>,
379 retired_slot: Box<AllocationSlotDescriptor>,
381 },
382 #[error("stable key '{stable_key}' was already retired")]
384 AlreadyRetired {
385 stable_key: StableKey,
387 slot: Box<AllocationSlotDescriptor>,
389 },
390}