1use crate::{
2 declaration::DeclarationSnapshotError,
3 key::{StableKey, StableKeyError},
4 ledger::LedgerPayloadEnvelopeError,
5 physical::CommitRecoveryError,
6 slot::MemoryManagerSlot,
7};
8
9#[non_exhaustive]
16#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
17pub enum LedgerIntegrityError {
18 #[error("ledger exceeds {resource} limit {limit}")]
20 LimitExceeded {
21 resource: &'static str,
22 limit: usize,
23 },
24 #[error("stable key '{stable_key}' appears in more than one allocation record")]
26 DuplicateStableKey {
27 stable_key: StableKey,
29 },
30 #[error("allocation slot '{slot:?}' appears in more than one allocation record")]
32 DuplicateSlot {
33 slot: MemoryManagerSlot,
35 },
36 #[error("stable key '{stable_key}' has first_generation after last_seen_generation")]
38 InvalidRecordGenerationOrder {
39 stable_key: StableKey,
41 first_generation: u64,
43 last_seen_generation: u64,
45 },
46 #[error(
48 "stable key '{stable_key}' references generation {generation} after current generation {current_generation}"
49 )]
50 FutureRecordGeneration {
51 stable_key: StableKey,
53 generation: u64,
55 current_generation: u64,
57 },
58 #[error("stable key '{stable_key}' was retired before first_generation")]
60 RetiredBeforeFirstGeneration {
61 stable_key: StableKey,
63 first_generation: u64,
65 retired_generation: u64,
67 },
68 #[error("stable key '{stable_key}' was retired at or before last_seen_generation")]
70 RetirementNotAfterLastSeen {
71 stable_key: StableKey,
73 last_seen_generation: u64,
75 retired_generation: u64,
77 },
78 #[error("stable key '{stable_key}' has empty schema metadata history")]
80 EmptySchemaHistory {
81 stable_key: StableKey,
83 },
84 #[error(
86 "stable key '{stable_key}' has schema metadata that does not begin at first_generation"
87 )]
88 SchemaHistoryStartMismatch {
89 stable_key: StableKey,
91 first_generation: u64,
93 schema_generation: u64,
95 },
96 #[error("stable key '{stable_key}' has non-increasing schema metadata generation history")]
98 NonIncreasingSchemaHistory {
99 stable_key: StableKey,
101 },
102 #[error("stable key '{stable_key}' has schema metadata generation outside the ledger bounds")]
104 SchemaHistoryOutOfBounds {
105 stable_key: StableKey,
107 generation: u64,
109 },
110 #[error("stable key '{stable_key}' has schema metadata after last_seen_generation")]
112 SchemaHistoryAfterLastSeen {
113 stable_key: StableKey,
115 generation: u64,
117 last_seen_generation: u64,
119 },
120 #[error("generation {generation} appears more than once")]
122 DuplicateGeneration {
123 generation: u64,
125 },
126 #[error("generation {generation} is after current generation {current_generation}")]
128 FutureGeneration {
129 generation: u64,
131 current_generation: u64,
133 },
134 #[error("generation {generation} has invalid parent generation {parent_generation}")]
136 InvalidParentGeneration {
137 generation: u64,
139 parent_generation: u64,
141 },
142 #[error("current generation {current_generation} has no committed generation record")]
144 MissingCurrentGenerationRecord {
145 current_generation: u64,
147 },
148 #[error("generation records are not strictly increasing at generation {generation}")]
150 NonIncreasingGenerationRecords {
151 generation: u64,
153 },
154 #[error(
156 "generation {generation} does not link to previous committed generation {expected_parent}"
157 )]
158 BrokenGenerationChain {
159 generation: u64,
161 expected_parent: u64,
163 actual_parent: u64,
165 },
166 #[error("stable key '{stable_key}' references unknown generation {generation}")]
168 UnknownRecordGeneration {
169 stable_key: StableKey,
171 generation: u64,
173 },
174 #[error(transparent)]
176 DiagnosticMetadata(DeclarationSnapshotError),
177}
178
179#[non_exhaustive]
184#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
185pub enum LedgerCommitError {
186 #[error(transparent)]
188 Recovery(CommitRecoveryError),
189 #[error(transparent)]
191 PayloadEnvelope(LedgerPayloadEnvelopeError),
192 #[error(
194 "physical generation {physical_generation} does not match logical ledger generation {logical_generation}"
195 )]
196 PhysicalLogicalGenerationMismatch {
197 physical_generation: u64,
199 logical_generation: u64,
201 },
202 #[error("allocation ledger codec failed: {0}")]
204 Codec(String),
205 #[error(transparent)]
207 Integrity(LedgerIntegrityError),
208}
209
210#[non_exhaustive]
217#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
218pub enum AllocationStageError {
219 #[error(transparent)]
220 Integrity(#[from] LedgerIntegrityError),
221 #[error(
223 "validated allocations were produced at generation {validated_generation}, but ledger is at generation {ledger_generation}"
224 )]
225 StaleValidatedAllocations {
226 validated_generation: u64,
228 ledger_generation: u64,
230 },
231 #[error("stable key '{stable_key}' was historically bound to a different allocation slot")]
233 StableKeySlotConflict {
234 stable_key: StableKey,
236 historical_slot: MemoryManagerSlot,
238 declared_slot: MemoryManagerSlot,
240 },
241 #[error("allocation slot '{slot:?}' was historically bound to stable key '{historical_key}'")]
243 SlotStableKeyConflict {
244 slot: MemoryManagerSlot,
246 historical_key: StableKey,
248 declared_key: StableKey,
250 },
251 #[error("stable key '{stable_key}' was explicitly retired and cannot be redeclared")]
253 RetiredAllocation {
254 stable_key: StableKey,
256 slot: MemoryManagerSlot,
258 },
259}
260
261#[non_exhaustive]
266#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
267pub enum AllocationReservationError {
268 #[error(transparent)]
269 Integrity(#[from] LedgerIntegrityError),
270 #[error("ledger generation {generation} cannot be advanced without overflow")]
272 GenerationOverflow {
273 generation: u64,
275 },
276 #[error("generation contains {count} reservations, exceeding the 255-allocation limit")]
278 TooManyReservations {
279 count: usize,
281 },
282 #[error("reservation declaration is invalid")]
284 InvalidDeclaration(#[source] DeclarationSnapshotError),
285 #[error("stable key '{stable_key}' was historically bound to a different allocation slot")]
287 StableKeySlotConflict {
288 stable_key: StableKey,
290 historical_slot: MemoryManagerSlot,
292 reserved_slot: MemoryManagerSlot,
294 },
295 #[error("allocation slot '{slot:?}' was historically bound to stable key '{historical_key}'")]
297 SlotStableKeyConflict {
298 slot: MemoryManagerSlot,
300 historical_key: StableKey,
302 reserved_key: StableKey,
304 },
305 #[error("stable key '{stable_key}' is already active and cannot be reserved")]
307 ActiveAllocation {
308 stable_key: StableKey,
310 slot: MemoryManagerSlot,
312 },
313 #[error("stable key '{stable_key}' was explicitly retired and cannot be reserved")]
315 RetiredAllocation {
316 stable_key: StableKey,
318 slot: MemoryManagerSlot,
320 },
321}
322
323#[non_exhaustive]
328#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
329pub enum AllocationRetirementError {
330 #[error(transparent)]
331 Integrity(#[from] LedgerIntegrityError),
332 #[error(transparent)]
334 Key(StableKeyError),
335 #[error("ledger generation {generation} cannot be advanced without overflow")]
337 GenerationOverflow {
338 generation: u64,
340 },
341 #[error("stable key '{0}' has no allocation record to retire")]
343 UnknownStableKey(StableKey),
344 #[error("stable key '{stable_key}' cannot be retired for a different allocation slot")]
346 SlotMismatch {
347 stable_key: StableKey,
349 historical_slot: MemoryManagerSlot,
351 retired_slot: MemoryManagerSlot,
353 },
354 #[error("stable key '{stable_key}' was already retired")]
356 AlreadyRetired {
357 stable_key: StableKey,
359 slot: MemoryManagerSlot,
361 },
362}