1use crate::{
2 declaration::DeclarationSnapshotError,
3 key::{StableKey, StableKeyError},
4 ledger::LedgerPayloadEnvelopeError,
5 physical::CommitRecoveryError,
6 schema::SchemaMetadataError,
7 slot::{AllocationSlotDescriptor, AllocationSlotDescriptorError},
8};
9
10#[derive(Clone, Copy, Debug, Eq, thiserror::Error, PartialEq)]
15pub enum LedgerCompatibilityError {
16 #[error(
18 "ledger_schema_version {found} is unsupported; supported range is {min_supported}-{max_supported}"
19 )]
20 UnsupportedLedgerSchemaVersion {
21 found: u32,
23 min_supported: u32,
25 max_supported: u32,
27 },
28 #[error("physical_format_id {found} is unsupported; supported format is {supported}")]
30 UnsupportedPhysicalFormat {
31 found: u32,
33 supported: u32,
35 },
36}
37
38#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
43pub enum LedgerIntegrityError {
44 #[error(transparent)]
46 InvalidStableKey(StableKeyError),
47 #[error(transparent)]
49 InvalidSlotDescriptor(AllocationSlotDescriptorError),
50 #[error("stable key '{stable_key}' appears in more than one allocation record")]
52 DuplicateStableKey {
53 stable_key: StableKey,
55 },
56 #[error("allocation slot '{slot:?}' appears in more than one allocation record")]
58 DuplicateSlot {
59 slot: Box<AllocationSlotDescriptor>,
61 },
62 #[error("stable key '{stable_key}' has first_generation after last_seen_generation")]
64 InvalidRecordGenerationOrder {
65 stable_key: StableKey,
67 first_generation: u64,
69 last_seen_generation: u64,
71 },
72 #[error(
74 "stable key '{stable_key}' references generation {generation} after current generation {current_generation}"
75 )]
76 FutureRecordGeneration {
77 stable_key: StableKey,
79 generation: u64,
81 current_generation: u64,
83 },
84 #[error("stable key '{stable_key}' is not retired but has retired_generation metadata")]
86 UnexpectedRetiredGeneration {
87 stable_key: StableKey,
89 },
90 #[error("stable key '{stable_key}' is retired but retired_generation is missing")]
92 MissingRetiredGeneration {
93 stable_key: StableKey,
95 },
96 #[error("stable key '{stable_key}' has retired_generation before first_generation")]
98 RetiredBeforeFirstGeneration {
99 stable_key: StableKey,
101 first_generation: u64,
103 retired_generation: u64,
105 },
106 #[error("stable key '{stable_key}' has empty schema metadata history")]
108 EmptySchemaHistory {
109 stable_key: StableKey,
111 },
112 #[error("stable key '{stable_key}' has non-increasing schema metadata generation history")]
114 NonIncreasingSchemaHistory {
115 stable_key: StableKey,
117 },
118 #[error("stable key '{stable_key}' has schema metadata generation outside the ledger bounds")]
120 SchemaHistoryOutOfBounds {
121 stable_key: StableKey,
123 generation: u64,
125 },
126 #[error("stable key '{stable_key}' has invalid schema metadata at generation {generation}")]
128 InvalidSchemaMetadata {
129 stable_key: StableKey,
131 generation: u64,
133 error: SchemaMetadataError,
135 },
136 #[error("generation {generation} appears more than once")]
138 DuplicateGeneration {
139 generation: u64,
141 },
142 #[error("generation {generation} is after current generation {current_generation}")]
144 FutureGeneration {
145 generation: u64,
147 current_generation: u64,
149 },
150 #[error("generation {generation} has invalid parent generation {parent_generation:?}")]
152 InvalidParentGeneration {
153 generation: u64,
155 parent_generation: Option<u64>,
157 },
158 #[error("current generation {current_generation} has no committed generation record")]
160 MissingCurrentGenerationRecord {
161 current_generation: u64,
163 },
164 #[error("generation records are not strictly increasing at generation {generation}")]
166 NonIncreasingGenerationRecords {
167 generation: u64,
169 },
170 #[error(
172 "generation {generation} does not link to previous committed generation {expected_parent:?}"
173 )]
174 BrokenGenerationChain {
175 generation: u64,
177 expected_parent: Option<u64>,
179 actual_parent: Option<u64>,
181 },
182 #[error("stable key '{stable_key}' references unknown generation {generation}")]
184 UnknownRecordGeneration {
185 stable_key: StableKey,
187 generation: u64,
189 },
190 #[error(transparent)]
192 DiagnosticMetadata(DeclarationSnapshotError),
193}
194
195#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
200pub enum LedgerCommitError {
201 #[error(transparent)]
203 Recovery(CommitRecoveryError),
204 #[error(transparent)]
206 PayloadEnvelope(LedgerPayloadEnvelopeError),
207 #[error(
209 "ledger payload envelope version {found} is unsupported; supported version is {supported}"
210 )]
211 UnsupportedEnvelopeVersion {
212 found: u16,
214 supported: u16,
216 },
217 #[error(
219 "physical generation {physical_generation} does not match logical ledger generation {logical_generation}"
220 )]
221 PhysicalLogicalGenerationMismatch {
222 physical_generation: u64,
224 logical_generation: u64,
226 },
227 #[error("ledger payload envelope metadata does not match decoded ledger metadata")]
229 PayloadEnvelopeLedgerMismatch {
230 envelope_ledger_schema_version: u32,
232 ledger_schema_version: u32,
234 envelope_physical_format_id: u32,
236 ledger_physical_format_id: u32,
238 },
239 #[error("allocation ledger codec failed")]
241 Codec(String),
242 #[error(transparent)]
244 Compatibility(LedgerCompatibilityError),
245 #[error(transparent)]
247 Integrity(LedgerIntegrityError),
248}
249
250#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
255pub enum AllocationStageError {
256 #[error(
258 "validated allocations were produced at generation {validated_generation}, but ledger is at generation {ledger_generation}"
259 )]
260 StaleValidatedAllocations {
261 validated_generation: u64,
263 ledger_generation: u64,
265 },
266 #[error("ledger generation {generation} cannot be advanced without overflow")]
268 GenerationOverflow {
269 generation: u64,
271 },
272 #[error("generation contains {count} declarations, exceeding the durable u32 diagnostic limit")]
274 TooManyDeclarations {
275 count: usize,
277 },
278 #[error("stable key '{stable_key}' has invalid schema metadata")]
280 InvalidSchemaMetadata {
281 stable_key: StableKey,
283 error: SchemaMetadataError,
285 },
286 #[error("stable key '{stable_key}' was historically bound to a different allocation slot")]
288 StableKeySlotConflict {
289 stable_key: StableKey,
291 historical_slot: Box<AllocationSlotDescriptor>,
293 declared_slot: Box<AllocationSlotDescriptor>,
295 },
296 #[error("allocation slot '{slot:?}' was historically bound to stable key '{historical_key}'")]
298 SlotStableKeyConflict {
299 slot: Box<AllocationSlotDescriptor>,
301 historical_key: StableKey,
303 declared_key: StableKey,
305 },
306 #[error("stable key '{stable_key}' was explicitly retired and cannot be redeclared")]
308 RetiredAllocation {
309 stable_key: StableKey,
311 slot: Box<AllocationSlotDescriptor>,
313 },
314}
315
316#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
321pub enum AllocationReservationError {
322 #[error("ledger generation {generation} cannot be advanced without overflow")]
324 GenerationOverflow {
325 generation: u64,
327 },
328 #[error("generation contains {count} reservations, exceeding the durable u32 diagnostic limit")]
330 TooManyReservations {
331 count: usize,
333 },
334 #[error("stable key '{stable_key}' has invalid schema metadata")]
336 InvalidSchemaMetadata {
337 stable_key: StableKey,
339 error: SchemaMetadataError,
341 },
342 #[error("stable key '{stable_key}' was historically bound to a different allocation slot")]
344 StableKeySlotConflict {
345 stable_key: StableKey,
347 historical_slot: Box<AllocationSlotDescriptor>,
349 reserved_slot: Box<AllocationSlotDescriptor>,
351 },
352 #[error("allocation slot '{slot:?}' was historically bound to stable key '{historical_key}'")]
354 SlotStableKeyConflict {
355 slot: Box<AllocationSlotDescriptor>,
357 historical_key: StableKey,
359 reserved_key: StableKey,
361 },
362 #[error("stable key '{stable_key}' is already active and cannot be reserved")]
364 ActiveAllocation {
365 stable_key: StableKey,
367 slot: Box<AllocationSlotDescriptor>,
369 },
370 #[error("stable key '{stable_key}' was explicitly retired and cannot be reserved")]
372 RetiredAllocation {
373 stable_key: StableKey,
375 slot: Box<AllocationSlotDescriptor>,
377 },
378}
379
380#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
385pub enum AllocationRetirementError {
386 #[error(transparent)]
388 Key(StableKeyError),
389 #[error("ledger generation {generation} cannot be advanced without overflow")]
391 GenerationOverflow {
392 generation: u64,
394 },
395 #[error("stable key '{0}' has no allocation record to retire")]
397 UnknownStableKey(StableKey),
398 #[error("stable key '{stable_key}' cannot be retired for a different allocation slot")]
400 SlotMismatch {
401 stable_key: StableKey,
403 historical_slot: Box<AllocationSlotDescriptor>,
405 retired_slot: Box<AllocationSlotDescriptor>,
407 },
408 #[error("stable key '{stable_key}' was already retired")]
410 AlreadyRetired {
411 stable_key: StableKey,
413 slot: Box<AllocationSlotDescriptor>,
415 },
416}