1use crate::{
2 declaration::DeclarationSnapshotError,
3 key::{StableKey, StableKeyError},
4 ledger::LedgerPayloadEnvelopeError,
5 physical::CommitRecoveryError,
6 schema::SchemaMetadataError,
7 slot::MemoryManagerSlot,
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("stable key '{stable_key}' appears in more than one allocation record")]
30 DuplicateStableKey {
31 stable_key: StableKey,
33 },
34 #[error("allocation slot '{slot:?}' appears in more than one allocation record")]
36 DuplicateSlot {
37 slot: MemoryManagerSlot,
39 },
40 #[error("stable key '{stable_key}' has first_generation after last_seen_generation")]
42 InvalidRecordGenerationOrder {
43 stable_key: StableKey,
45 first_generation: u64,
47 last_seen_generation: u64,
49 },
50 #[error(
52 "stable key '{stable_key}' references generation {generation} after current generation {current_generation}"
53 )]
54 FutureRecordGeneration {
55 stable_key: StableKey,
57 generation: u64,
59 current_generation: u64,
61 },
62 #[error("stable key '{stable_key}' was retired before first_generation")]
64 RetiredBeforeFirstGeneration {
65 stable_key: StableKey,
67 first_generation: u64,
69 retired_generation: u64,
71 },
72 #[error("stable key '{stable_key}' was retired at or before last_seen_generation")]
74 RetirementNotAfterLastSeen {
75 stable_key: StableKey,
77 last_seen_generation: u64,
79 retired_generation: u64,
81 },
82 #[error("stable key '{stable_key}' has empty schema metadata history")]
84 EmptySchemaHistory {
85 stable_key: StableKey,
87 },
88 #[error(
90 "stable key '{stable_key}' has schema metadata that does not begin at first_generation"
91 )]
92 SchemaHistoryStartMismatch {
93 stable_key: StableKey,
95 first_generation: u64,
97 schema_generation: u64,
99 },
100 #[error("stable key '{stable_key}' has non-increasing schema metadata generation history")]
102 NonIncreasingSchemaHistory {
103 stable_key: StableKey,
105 },
106 #[error("stable key '{stable_key}' has schema metadata generation outside the ledger bounds")]
108 SchemaHistoryOutOfBounds {
109 stable_key: StableKey,
111 generation: u64,
113 },
114 #[error("stable key '{stable_key}' has schema metadata after last_seen_generation")]
116 SchemaHistoryAfterLastSeen {
117 stable_key: StableKey,
119 generation: u64,
121 last_seen_generation: u64,
123 },
124 #[error("stable key '{stable_key}' has invalid schema metadata at generation {generation}")]
126 InvalidSchemaMetadata {
127 stable_key: StableKey,
129 generation: u64,
131 error: SchemaMetadataError,
133 },
134 #[error("generation {generation} appears more than once")]
136 DuplicateGeneration {
137 generation: u64,
139 },
140 #[error("generation {generation} is after current generation {current_generation}")]
142 FutureGeneration {
143 generation: u64,
145 current_generation: u64,
147 },
148 #[error("generation {generation} has invalid parent generation {parent_generation}")]
150 InvalidParentGeneration {
151 generation: u64,
153 parent_generation: u64,
155 },
156 #[error("current generation {current_generation} has no committed generation record")]
158 MissingCurrentGenerationRecord {
159 current_generation: u64,
161 },
162 #[error("generation records are not strictly increasing at generation {generation}")]
164 NonIncreasingGenerationRecords {
165 generation: u64,
167 },
168 #[error(
170 "generation {generation} does not link to previous committed generation {expected_parent}"
171 )]
172 BrokenGenerationChain {
173 generation: u64,
175 expected_parent: u64,
177 actual_parent: u64,
179 },
180 #[error("stable key '{stable_key}' references unknown generation {generation}")]
182 UnknownRecordGeneration {
183 stable_key: StableKey,
185 generation: u64,
187 },
188 #[error(transparent)]
190 DiagnosticMetadata(DeclarationSnapshotError),
191}
192
193#[non_exhaustive]
198#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
199pub enum LedgerCommitError {
200 #[error(transparent)]
202 Recovery(CommitRecoveryError),
203 #[error(transparent)]
205 PayloadEnvelope(LedgerPayloadEnvelopeError),
206 #[error(
208 "physical generation {physical_generation} does not match logical ledger generation {logical_generation}"
209 )]
210 PhysicalLogicalGenerationMismatch {
211 physical_generation: u64,
213 logical_generation: u64,
215 },
216 #[error("allocation ledger codec failed: {0}")]
218 Codec(String),
219 #[error(transparent)]
221 Integrity(LedgerIntegrityError),
222}
223
224#[non_exhaustive]
231#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
232pub enum AllocationStageError {
233 #[error(transparent)]
234 Integrity(#[from] LedgerIntegrityError),
235 #[error(
237 "validated allocations were produced at generation {validated_generation}, but ledger is at generation {ledger_generation}"
238 )]
239 StaleValidatedAllocations {
240 validated_generation: u64,
242 ledger_generation: u64,
244 },
245 #[error("stable key '{stable_key}' was historically bound to a different allocation slot")]
247 StableKeySlotConflict {
248 stable_key: StableKey,
250 historical_slot: MemoryManagerSlot,
252 declared_slot: MemoryManagerSlot,
254 },
255 #[error("allocation slot '{slot:?}' was historically bound to stable key '{historical_key}'")]
257 SlotStableKeyConflict {
258 slot: MemoryManagerSlot,
260 historical_key: StableKey,
262 declared_key: StableKey,
264 },
265 #[error("stable key '{stable_key}' was explicitly retired and cannot be redeclared")]
267 RetiredAllocation {
268 stable_key: StableKey,
270 slot: MemoryManagerSlot,
272 },
273}
274
275#[non_exhaustive]
280#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
281pub enum AllocationReservationError {
282 #[error(transparent)]
283 Integrity(#[from] LedgerIntegrityError),
284 #[error("ledger generation {generation} cannot be advanced without overflow")]
286 GenerationOverflow {
287 generation: u64,
289 },
290 #[error("generation contains {count} reservations, exceeding the 255-allocation limit")]
292 TooManyReservations {
293 count: usize,
295 },
296 #[error("stable key '{stable_key}' has invalid schema metadata")]
298 InvalidSchemaMetadata {
299 stable_key: StableKey,
301 error: SchemaMetadataError,
303 },
304 #[error("reservation declaration is invalid")]
306 InvalidDeclaration(#[source] DeclarationSnapshotError),
307 #[error("stable key '{stable_key}' was historically bound to a different allocation slot")]
309 StableKeySlotConflict {
310 stable_key: StableKey,
312 historical_slot: MemoryManagerSlot,
314 reserved_slot: MemoryManagerSlot,
316 },
317 #[error("allocation slot '{slot:?}' was historically bound to stable key '{historical_key}'")]
319 SlotStableKeyConflict {
320 slot: MemoryManagerSlot,
322 historical_key: StableKey,
324 reserved_key: StableKey,
326 },
327 #[error("stable key '{stable_key}' is already active and cannot be reserved")]
329 ActiveAllocation {
330 stable_key: StableKey,
332 slot: MemoryManagerSlot,
334 },
335 #[error("stable key '{stable_key}' was explicitly retired and cannot be reserved")]
337 RetiredAllocation {
338 stable_key: StableKey,
340 slot: MemoryManagerSlot,
342 },
343}
344
345#[non_exhaustive]
350#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
351pub enum AllocationRetirementError {
352 #[error(transparent)]
353 Integrity(#[from] LedgerIntegrityError),
354 #[error(transparent)]
356 Key(StableKeyError),
357 #[error("ledger generation {generation} cannot be advanced without overflow")]
359 GenerationOverflow {
360 generation: u64,
362 },
363 #[error("stable key '{0}' has no allocation record to retire")]
365 UnknownStableKey(StableKey),
366 #[error("stable key '{stable_key}' cannot be retired for a different allocation slot")]
368 SlotMismatch {
369 stable_key: StableKey,
371 historical_slot: MemoryManagerSlot,
373 retired_slot: MemoryManagerSlot,
375 },
376 #[error("stable key '{stable_key}' was already retired")]
378 AlreadyRetired {
379 stable_key: StableKey,
381 slot: MemoryManagerSlot,
383 },
384}