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/// LedgerCommitError
31///
32/// Failure to recover or commit a logical allocation ledger.
33#[non_exhaustive]
34#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
35pub enum LedgerCommitError {
36    /// Protected physical commit recovery failed.
37    #[error(transparent)]
38    Recovery(CommitRecoveryError),
39    /// Built-in ledger decoding failed.
40    #[error("allocation ledger codec failed: {0}")]
41    Codec(String),
42    /// Decoded ledger violates current ownership invariants.
43    #[error(transparent)]
44    Integrity(LedgerIntegrityError),
45}
46
47///
48/// AllocationStageError
49///
50/// Failure to stage a validated allocation generation.
51///
52
53#[non_exhaustive]
54#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
55pub enum AllocationStageError {
56    /// The commit counter cannot advance without overflow.
57    #[error("ledger generation {generation} cannot be advanced without overflow")]
58    GenerationOverflow { generation: u64 },
59    #[error(transparent)]
60    Integrity(#[from] LedgerIntegrityError),
61}