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 composed consumer rejected the sealed snapshot before commitment.
20    #[error("composed memory admission rejected: {source}")]
21    Admission {
22        #[source]
23        source: Box<dyn std::error::Error + Send + Sync>,
24    },
25
26    /// Exactly one artifact owner may compose consumer admission.
27    #[error("memory admission is already registered")]
28    AdmissionAlreadyRegistered,
29
30    /// Admission cannot change after Canic has selected its bootstrap policy.
31    #[error("memory admission registration is sealed")]
32    AdmissionRegistrationSealed,
33
34    /// A poisoned registry cannot supply trustworthy admission authority.
35    #[error("memory admission registry is poisoned")]
36    AdmissionRegistryPoisoned,
37
38    /// A declaration was rejected before or during `ic-memory` validation.
39    #[error("memory declaration rejected for stable key '{stable_key}': {reason}")]
40    InvalidDeclaration {
41        stable_key: String,
42        reason: &'static str,
43    },
44
45    /// The stable key namespace and memory ID range do not match.
46    #[error(
47        "memory stable key '{stable_key}' with id {id} violates namespace/range authority: {reason}"
48    )]
49    RangeAuthorityViolation {
50        /// Stable key being registered.
51        stable_key: String,
52        /// Stable-memory ID being registered.
53        id: u8,
54        /// Human-readable reason for the rejection.
55        reason: &'static str,
56    },
57}