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("stable key '{stable_key}' appears in more than one allocation record")]
27 DuplicateStableKey {
28 stable_key: StableKey,
30 },
31 #[error("allocation slot '{slot:?}' appears in more than one allocation record")]
33 DuplicateSlot {
34 slot: MemoryManagerSlot,
36 },
37 #[error("stable key '{stable_key}' has first_generation after last_seen_generation")]
39 InvalidRecordGenerationOrder {
40 stable_key: StableKey,
42 first_generation: u64,
44 last_seen_generation: u64,
46 },
47 #[error(
49 "stable key '{stable_key}' references generation {generation} after current generation {current_generation}"
50 )]
51 FutureRecordGeneration {
52 stable_key: StableKey,
54 generation: u64,
56 current_generation: u64,
58 },
59 #[error("stable key '{stable_key}' was retired before first_generation")]
61 RetiredBeforeFirstGeneration {
62 stable_key: StableKey,
64 first_generation: u64,
66 retired_generation: u64,
68 },
69 #[error("stable key '{stable_key}' was retired at or before last_seen_generation")]
71 RetirementNotAfterLastSeen {
72 stable_key: StableKey,
74 last_seen_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(
87 "stable key '{stable_key}' has schema metadata that does not begin at first_generation"
88 )]
89 SchemaHistoryStartMismatch {
90 stable_key: StableKey,
92 first_generation: u64,
94 schema_generation: u64,
96 },
97 #[error("stable key '{stable_key}' has non-increasing schema metadata generation history")]
99 NonIncreasingSchemaHistory {
100 stable_key: StableKey,
102 },
103 #[error("stable key '{stable_key}' has schema metadata generation outside the ledger bounds")]
105 SchemaHistoryOutOfBounds {
106 stable_key: StableKey,
108 generation: u64,
110 },
111 #[error("stable key '{stable_key}' has schema metadata after last_seen_generation")]
113 SchemaHistoryAfterLastSeen {
114 stable_key: StableKey,
116 generation: u64,
118 last_seen_generation: u64,
120 },
121 #[error("stable key '{stable_key}' has invalid schema metadata at generation {generation}")]
123 InvalidSchemaMetadata {
124 stable_key: StableKey,
126 generation: u64,
128 error: SchemaMetadataError,
130 },
131 #[error("generation {generation} appears more than once")]
133 DuplicateGeneration {
134 generation: u64,
136 },
137 #[error("generation {generation} is after current generation {current_generation}")]
139 FutureGeneration {
140 generation: u64,
142 current_generation: u64,
144 },
145 #[error("generation {generation} has invalid parent generation {parent_generation}")]
147 InvalidParentGeneration {
148 generation: u64,
150 parent_generation: u64,
152 },
153 #[error("current generation {current_generation} has no committed generation record")]
155 MissingCurrentGenerationRecord {
156 current_generation: u64,
158 },
159 #[error("generation records are not strictly increasing at generation {generation}")]
161 NonIncreasingGenerationRecords {
162 generation: u64,
164 },
165 #[error(
167 "generation {generation} does not link to previous committed generation {expected_parent}"
168 )]
169 BrokenGenerationChain {
170 generation: u64,
172 expected_parent: u64,
174 actual_parent: u64,
176 },
177 #[error("stable key '{stable_key}' references unknown generation {generation}")]
179 UnknownRecordGeneration {
180 stable_key: StableKey,
182 generation: u64,
184 },
185 #[error(transparent)]
187 DiagnosticMetadata(DeclarationSnapshotError),
188}
189
190#[non_exhaustive]
195#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
196pub enum LedgerCommitError {
197 #[error(transparent)]
199 Recovery(CommitRecoveryError),
200 #[error(transparent)]
202 PayloadEnvelope(LedgerPayloadEnvelopeError),
203 #[error(
205 "physical generation {physical_generation} does not match logical ledger generation {logical_generation}"
206 )]
207 PhysicalLogicalGenerationMismatch {
208 physical_generation: u64,
210 logical_generation: u64,
212 },
213 #[error("allocation ledger codec failed: {0}")]
215 Codec(String),
216 #[error(transparent)]
218 Integrity(LedgerIntegrityError),
219}
220
221#[non_exhaustive]
228#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
229pub enum AllocationStageError {
230 #[error(transparent)]
231 Integrity(#[from] LedgerIntegrityError),
232 #[error(
234 "validated allocations were produced at generation {validated_generation}, but ledger is at generation {ledger_generation}"
235 )]
236 StaleValidatedAllocations {
237 validated_generation: u64,
239 ledger_generation: u64,
241 },
242 #[error("stable key '{stable_key}' was historically bound to a different allocation slot")]
244 StableKeySlotConflict {
245 stable_key: StableKey,
247 historical_slot: MemoryManagerSlot,
249 declared_slot: MemoryManagerSlot,
251 },
252 #[error("allocation slot '{slot:?}' was historically bound to stable key '{historical_key}'")]
254 SlotStableKeyConflict {
255 slot: MemoryManagerSlot,
257 historical_key: StableKey,
259 declared_key: StableKey,
261 },
262 #[error("stable key '{stable_key}' was explicitly retired and cannot be redeclared")]
264 RetiredAllocation {
265 stable_key: StableKey,
267 slot: MemoryManagerSlot,
269 },
270}
271
272#[non_exhaustive]
277#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
278pub enum AllocationReservationError {
279 #[error(transparent)]
280 Integrity(#[from] LedgerIntegrityError),
281 #[error("ledger generation {generation} cannot be advanced without overflow")]
283 GenerationOverflow {
284 generation: u64,
286 },
287 #[error("generation contains {count} reservations, exceeding the 255-allocation limit")]
289 TooManyReservations {
290 count: usize,
292 },
293 #[error("stable key '{stable_key}' has invalid schema metadata")]
295 InvalidSchemaMetadata {
296 stable_key: StableKey,
298 error: SchemaMetadataError,
300 },
301 #[error("reservation declaration is invalid")]
303 InvalidDeclaration(#[source] DeclarationSnapshotError),
304 #[error("stable key '{stable_key}' was historically bound to a different allocation slot")]
306 StableKeySlotConflict {
307 stable_key: StableKey,
309 historical_slot: MemoryManagerSlot,
311 reserved_slot: MemoryManagerSlot,
313 },
314 #[error("allocation slot '{slot:?}' was historically bound to stable key '{historical_key}'")]
316 SlotStableKeyConflict {
317 slot: MemoryManagerSlot,
319 historical_key: StableKey,
321 reserved_key: StableKey,
323 },
324 #[error("stable key '{stable_key}' is already active and cannot be reserved")]
326 ActiveAllocation {
327 stable_key: StableKey,
329 slot: MemoryManagerSlot,
331 },
332 #[error("stable key '{stable_key}' was explicitly retired and cannot be reserved")]
334 RetiredAllocation {
335 stable_key: StableKey,
337 slot: MemoryManagerSlot,
339 },
340}
341
342#[non_exhaustive]
347#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
348pub enum AllocationRetirementError {
349 #[error(transparent)]
350 Integrity(#[from] LedgerIntegrityError),
351 #[error(transparent)]
353 Key(StableKeyError),
354 #[error("ledger generation {generation} cannot be advanced without overflow")]
356 GenerationOverflow {
357 generation: u64,
359 },
360 #[error("stable key '{0}' has no allocation record to retire")]
362 UnknownStableKey(StableKey),
363 #[error("stable key '{stable_key}' cannot be retired for a different allocation slot")]
365 SlotMismatch {
366 stable_key: StableKey,
368 historical_slot: MemoryManagerSlot,
370 retired_slot: MemoryManagerSlot,
372 },
373 #[error("stable key '{stable_key}' was already retired")]
375 AlreadyRetired {
376 stable_key: StableKey,
378 slot: MemoryManagerSlot,
380 },
381}