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#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
15pub enum LedgerIntegrityError {
16 #[error(transparent)]
18 InvalidStableKey(StableKeyError),
19 #[error(transparent)]
21 InvalidSlotDescriptor(MemoryManagerSlotError),
22 #[error("stable key '{stable_key}' appears in more than one allocation record")]
24 DuplicateStableKey {
25 stable_key: StableKey,
27 },
28 #[error("allocation slot '{slot:?}' appears in more than one allocation record")]
30 DuplicateSlot {
31 slot: Box<AllocationSlotDescriptor>,
33 },
34 #[error("stable key '{stable_key}' has first_generation after last_seen_generation")]
36 InvalidRecordGenerationOrder {
37 stable_key: StableKey,
39 first_generation: u64,
41 last_seen_generation: u64,
43 },
44 #[error(
46 "stable key '{stable_key}' references generation {generation} after current generation {current_generation}"
47 )]
48 FutureRecordGeneration {
49 stable_key: StableKey,
51 generation: u64,
53 current_generation: u64,
55 },
56 #[error("stable key '{stable_key}' is not retired but has retired_generation metadata")]
58 UnexpectedRetiredGeneration {
59 stable_key: StableKey,
61 },
62 #[error("stable key '{stable_key}' is retired but retired_generation is missing")]
64 MissingRetiredGeneration {
65 stable_key: StableKey,
67 },
68 #[error("stable key '{stable_key}' has retired_generation before first_generation")]
70 RetiredBeforeFirstGeneration {
71 stable_key: StableKey,
73 first_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("stable key '{stable_key}' has non-increasing schema metadata generation history")]
86 NonIncreasingSchemaHistory {
87 stable_key: StableKey,
89 },
90 #[error("stable key '{stable_key}' has schema metadata generation outside the ledger bounds")]
92 SchemaHistoryOutOfBounds {
93 stable_key: StableKey,
95 generation: u64,
97 },
98 #[error("stable key '{stable_key}' has invalid schema metadata at generation {generation}")]
100 InvalidSchemaMetadata {
101 stable_key: StableKey,
103 generation: u64,
105 error: SchemaMetadataError,
107 },
108 #[error("generation {generation} appears more than once")]
110 DuplicateGeneration {
111 generation: u64,
113 },
114 #[error("generation {generation} is after current generation {current_generation}")]
116 FutureGeneration {
117 generation: u64,
119 current_generation: u64,
121 },
122 #[error("generation {generation} has invalid parent generation {parent_generation}")]
124 InvalidParentGeneration {
125 generation: u64,
127 parent_generation: u64,
129 },
130 #[error("current generation {current_generation} has no committed generation record")]
132 MissingCurrentGenerationRecord {
133 current_generation: u64,
135 },
136 #[error("generation records are not strictly increasing at generation {generation}")]
138 NonIncreasingGenerationRecords {
139 generation: u64,
141 },
142 #[error(
144 "generation {generation} does not link to previous committed generation {expected_parent}"
145 )]
146 BrokenGenerationChain {
147 generation: u64,
149 expected_parent: u64,
151 actual_parent: u64,
153 },
154 #[error("stable key '{stable_key}' references unknown generation {generation}")]
156 UnknownRecordGeneration {
157 stable_key: StableKey,
159 generation: u64,
161 },
162 #[error(transparent)]
164 DiagnosticMetadata(DeclarationSnapshotError),
165}
166
167#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
172pub enum LedgerCommitError {
173 #[error(transparent)]
175 Recovery(CommitRecoveryError),
176 #[error(transparent)]
178 PayloadEnvelope(LedgerPayloadEnvelopeError),
179 #[error(
181 "physical generation {physical_generation} does not match logical ledger generation {logical_generation}"
182 )]
183 PhysicalLogicalGenerationMismatch {
184 physical_generation: u64,
186 logical_generation: u64,
188 },
189 #[error("allocation ledger codec failed")]
191 Codec(String),
192 #[error(transparent)]
194 Integrity(LedgerIntegrityError),
195}
196
197#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
202pub enum AllocationStageError {
203 #[error(
205 "validated allocations were produced at generation {validated_generation}, but ledger is at generation {ledger_generation}"
206 )]
207 StaleValidatedAllocations {
208 validated_generation: u64,
210 ledger_generation: u64,
212 },
213 #[error("ledger generation {generation} cannot be advanced without overflow")]
215 GenerationOverflow {
216 generation: u64,
218 },
219 #[error("generation contains {count} declarations, exceeding the durable u32 diagnostic limit")]
221 TooManyDeclarations {
222 count: usize,
224 },
225 #[error("stable key '{stable_key}' has invalid schema metadata")]
227 InvalidSchemaMetadata {
228 stable_key: StableKey,
230 error: SchemaMetadataError,
232 },
233 #[error("stable key '{stable_key}' was historically bound to a different allocation slot")]
235 StableKeySlotConflict {
236 stable_key: StableKey,
238 historical_slot: Box<AllocationSlotDescriptor>,
240 declared_slot: Box<AllocationSlotDescriptor>,
242 },
243 #[error("allocation slot '{slot:?}' was historically bound to stable key '{historical_key}'")]
245 SlotStableKeyConflict {
246 slot: Box<AllocationSlotDescriptor>,
248 historical_key: StableKey,
250 declared_key: StableKey,
252 },
253 #[error("stable key '{stable_key}' was explicitly retired and cannot be redeclared")]
255 RetiredAllocation {
256 stable_key: StableKey,
258 slot: Box<AllocationSlotDescriptor>,
260 },
261}
262
263#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
268pub enum AllocationReservationError {
269 #[error("ledger generation {generation} cannot be advanced without overflow")]
271 GenerationOverflow {
272 generation: u64,
274 },
275 #[error("generation contains {count} reservations, exceeding the durable u32 diagnostic limit")]
277 TooManyReservations {
278 count: usize,
280 },
281 #[error("stable key '{stable_key}' has invalid schema metadata")]
283 InvalidSchemaMetadata {
284 stable_key: StableKey,
286 error: SchemaMetadataError,
288 },
289 #[error("stable key '{stable_key}' was historically bound to a different allocation slot")]
291 StableKeySlotConflict {
292 stable_key: StableKey,
294 historical_slot: Box<AllocationSlotDescriptor>,
296 reserved_slot: Box<AllocationSlotDescriptor>,
298 },
299 #[error("allocation slot '{slot:?}' was historically bound to stable key '{historical_key}'")]
301 SlotStableKeyConflict {
302 slot: Box<AllocationSlotDescriptor>,
304 historical_key: StableKey,
306 reserved_key: StableKey,
308 },
309 #[error("stable key '{stable_key}' is already active and cannot be reserved")]
311 ActiveAllocation {
312 stable_key: StableKey,
314 slot: Box<AllocationSlotDescriptor>,
316 },
317 #[error("stable key '{stable_key}' was explicitly retired and cannot be reserved")]
319 RetiredAllocation {
320 stable_key: StableKey,
322 slot: Box<AllocationSlotDescriptor>,
324 },
325}
326
327#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
332pub enum AllocationRetirementError {
333 #[error(transparent)]
335 Key(StableKeyError),
336 #[error("ledger generation {generation} cannot be advanced without overflow")]
338 GenerationOverflow {
339 generation: u64,
341 },
342 #[error("stable key '{0}' has no allocation record to retire")]
344 UnknownStableKey(StableKey),
345 #[error("stable key '{stable_key}' cannot be retired for a different allocation slot")]
347 SlotMismatch {
348 stable_key: StableKey,
350 historical_slot: Box<AllocationSlotDescriptor>,
352 retired_slot: Box<AllocationSlotDescriptor>,
354 },
355 #[error("stable key '{stable_key}' was already retired")]
357 AlreadyRetired {
358 stable_key: StableKey,
360 slot: Box<AllocationSlotDescriptor>,
362 },
363}