Skip to main content

ic_memory/ledger/
error.rs

1use crate::{key::StableKey, physical::CommitRecoveryError, slot::MemoryManagerSlot};
2
3///
4/// LedgerIntegrityError
5///
6/// Decoded ledger violates current ownership invariants.
7///
8
9#[non_exhaustive]
10#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
11pub enum LedgerIntegrityError {
12    /// Current structural recovery ceiling exceeded.
13    #[error("ledger exceeds {resource} limit {limit}")]
14    LimitExceeded {
15        resource: &'static str,
16        limit: usize,
17    },
18    /// Stable key appears in more than one retained allocation record.
19    #[error("stable key '{stable_key}' appears in more than one allocation record")]
20    DuplicateStableKey { stable_key: StableKey },
21    /// Memory ID appears in more than one retained allocation record.
22    #[error("allocation slot '{slot:?}' appears in more than one allocation record")]
23    DuplicateSlot { slot: MemoryManagerSlot },
24    /// Commit counter zero is reserved for empty genesis.
25    #[error("genesis ledger contains allocation records")]
26    NonemptyGenesis,
27}
28
29///
30/// LedgerDecodeError
31///
32/// Typed source of a logical ledger decoding failure. Decoded rows still
33/// require ledger integrity validation before granting allocation authority.
34///
35
36#[non_exhaustive]
37#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
38pub enum LedgerDecodeError {
39    /// IC Wire refused syntax, trailing bytes or traversal budgets.
40    #[error(transparent)]
41    Wire(#[from] ic_wire::Error),
42    /// A stored logical key violates its bounded grammar.
43    #[error(transparent)]
44    Key(#[from] crate::StableKeyError),
45    /// A stored slot is outside the usable manager ID domain.
46    #[error(transparent)]
47    Slot(#[from] crate::MemoryManagerSlotError),
48}
49
50///
51/// LedgerCommitError
52///
53/// Failure to recover or commit a logical allocation ledger.
54#[non_exhaustive]
55#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
56pub enum LedgerCommitError {
57    /// Protected physical commit recovery failed.
58    #[error(transparent)]
59    Recovery(CommitRecoveryError),
60    /// Built-in ledger decoding failed.
61    #[error("allocation ledger codec failed: {0}")]
62    Codec(#[source] LedgerDecodeError),
63    /// Decoded ledger violates current ownership invariants.
64    #[error(transparent)]
65    Integrity(LedgerIntegrityError),
66}
67
68///
69/// AllocationStageError
70///
71/// Failure to stage a validated allocation generation.
72///
73
74#[non_exhaustive]
75#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
76pub enum AllocationStageError {
77    /// The commit counter cannot advance without overflow.
78    #[error("ledger generation {generation} cannot be advanced without overflow")]
79    GenerationOverflow { generation: u64 },
80    #[error(transparent)]
81    Integrity(#[from] LedgerIntegrityError),
82}