canic-core 0.110.2

Canic — a canister orchestration and management toolkit for the Internet Computer
Documentation
//! Persisted record and stable-memory representation.
//!
//! This module contains passive persisted and cached representations. Model
//! owns authoritative state and storage invariants; ops owns access and
//! conversion at this boundary.
//!
//! Multi-step orchestration lives in `workflow`; pure decision helpers live in
//! `domain::policy::pure`.

pub mod canister;
pub mod stable;

///
/// Prelude
///

pub mod prelude {
    pub use crate::impl_storable_bounded;
    pub use crate::{
        cdk::types::{Cycles, Principal},
        eager_static,
        ids::{CanisterRole, ComponentSpecId, ManagedCanisterBinding},
    };
    pub use serde::{Deserialize, Serialize};
}

use crate::InternalError;
use thiserror::Error as ThisError;

///
/// StorageError
///

#[derive(Debug, ThisError)]
pub enum StorageError {
    #[error("runtime log count invariant is inconsistent")]
    LogCountInvariant,

    #[error("runtime log sequence {0} already exists")]
    LogSequenceConflict(u64),

    #[error("runtime log sequence exhausted")]
    LogSequenceExhausted,

    #[error("runtime log timestamp regressed from {previous} to {current}")]
    LogTimestampRegressed { previous: u64, current: u64 },
}

impl From<StorageError> for InternalError {
    fn from(err: StorageError) -> Self {
        use crate::diagnostics::codes;

        let code = match err {
            StorageError::LogCountInvariant => codes::STATE_INVALID,
            StorageError::LogSequenceConflict(_) => codes::POSITION_CONFLICT,
            StorageError::LogSequenceExhausted => codes::VERSION_CAPACITY,
            StorageError::LogTimestampRegressed { .. } => codes::TIME_ORDERING,
        };
        Self::public(code)
    }
}