Skip to main content

canic_core/memory/
registry.rs

1//! Module: memory::registry
2//!
3//! Responsibility: define memory registry bootstrap and validation errors.
4//! Does not own: allocation policy, stable schemas, or memory-manager storage.
5//! Boundary: memory bootstrap maps `ic-memory` validation failures into this type.
6
7use thiserror::Error as ThisError;
8
9///
10/// MemoryRegistryError
11///
12/// Canic-facing errors returned while bootstrapping or reading the
13/// `ic-memory` allocation ledger.
14/// Owned by memory registry and returned to lifecycle/bootstrap callers.
15///
16
17#[derive(Debug, ThisError)]
18pub enum MemoryRegistryError {
19    /// A declaration was rejected before or during `ic-memory` validation.
20    #[error("memory declaration rejected for stable key '{stable_key}': {reason}")]
21    InvalidDeclaration {
22        stable_key: String,
23        reason: &'static str,
24    },
25
26    /// The stable key namespace and memory ID range do not match.
27    #[error(
28        "memory stable key '{stable_key}' with id {id} violates namespace/range authority: {reason}"
29    )]
30    RangeAuthorityViolation {
31        /// Stable key being registered.
32        stable_key: String,
33        /// Stable-memory ID being registered.
34        id: u8,
35        /// Human-readable reason for the rejection.
36        reason: &'static str,
37    },
38
39    /// The persisted ABI ledger cannot be validated.
40    #[error("memory layout ledger is corrupt: {reason}")]
41    LedgerCorrupt {
42        /// Human-readable corruption reason.
43        reason: &'static str,
44    },
45}