use crate::{
LedgerCommitError, PolicyIdentity, PolicyIdentityError, StableCellLedgerError,
registry::StaticMemoryDeclarationError,
slot::{MemoryManagerRangeAuthorityError, MemoryManagerSlotError},
};
#[non_exhaustive]
#[derive(Clone, Copy, Debug, Eq, thiserror::Error, PartialEq)]
pub enum RuntimeConstructionError {
#[error("bucket size must be nonzero")]
InvalidBucketSize,
#[error("persisted bucket size {persisted} pages differs from requested {requested}")]
BucketSizeMismatch { persisted: u16, requested: u16 },
#[error(transparent)]
Layout(#[from] super::MemoryManagerLayoutError),
#[error(
"nonempty backing memory is not an ic-stable-structures MemoryManager \
(expected magic 'MGR', found bytes {observed_magic:?})"
)]
ForeignMemory {
observed_magic: [u8; 3],
},
#[error(
"unsupported ic-stable-structures MemoryManager layout version {observed}; \
expected {supported}"
)]
UnsupportedMemoryManagerVersion {
observed: u8,
supported: u8,
},
}
#[non_exhaustive]
#[derive(Clone, Copy, Debug, Eq, thiserror::Error, PartialEq)]
pub enum RuntimeStateError {
#[error(transparent)]
Construction(#[from] RuntimeConstructionError),
#[error("ic-memory default runtime is already borrowed by an active operation")]
ReentrantAccess,
#[error("ic-memory default runtime is unavailable during thread-local destruction")]
Unavailable,
#[error("ic-memory runtime lifecycle is internally inconsistent")]
InconsistentLifecycle,
}
#[non_exhaustive]
#[derive(Debug, thiserror::Error)]
pub enum RuntimeBootstrapError<P> {
#[error(transparent)]
PolicyIdentity(#[from] PolicyIdentityError),
#[error("runtime bootstrap declaration snapshot differs from the established binding")]
DeclarationSnapshotMismatch,
#[error("runtime bootstrap policy identity changed from {established:?} to {requested:?}")]
PolicyIdentityMismatch {
established: PolicyIdentity,
requested: PolicyIdentity,
},
#[error(transparent)]
Registry(#[from] StaticMemoryDeclarationError),
#[error(transparent)]
LedgerIntegrity(#[from] crate::LedgerIntegrityError),
#[error(transparent)]
LedgerCommit(#[from] crate::LedgerCommitError),
#[error(transparent)]
StableCellLedger(#[from] StableCellLedgerError),
#[error("stable-cell ledger record size {value_size} cannot be written to stable memory")]
StableCellLedgerWriteTooLarge {
value_size: usize,
},
#[error(transparent)]
Validation(#[from] crate::AllocationValidationError<RuntimePolicyError<P>>),
#[error(transparent)]
Staging(#[from] crate::AllocationStageError),
#[error(transparent)]
State(#[from] RuntimeStateError),
}
#[non_exhaustive]
#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
pub enum RuntimeOpenError {
#[error("ic-memory runtime has not completed bootstrap validation")]
NotBootstrapped,
#[error(transparent)]
State(#[from] RuntimeStateError),
#[error(transparent)]
StableKey(#[from] crate::StableKeyError),
#[error("stable key '{0}' was not committed by ic-memory runtime bootstrap")]
StableKeyNotCommitted(String),
#[error("stable key '{stable_key}' is reserved for ic-memory runtime governance")]
ReservedStableKey {
stable_key: String,
},
#[error(transparent)]
MemoryManagerSlot(#[from] MemoryManagerSlotError),
#[error(
"stable key '{stable_key}' is committed for MemoryManager ID {committed_id}, not requested ID {requested_id}"
)]
MemoryIdMismatch {
stable_key: String,
committed_id: u8,
requested_id: u8,
},
}
#[non_exhaustive]
#[derive(Debug, thiserror::Error)]
pub enum RuntimeDiagnosticError {
#[error(transparent)]
Construction(#[from] RuntimeConstructionError),
#[error("allocation bindings exceed the bounded manager domain")]
AllocationBound,
#[error("ic-memory runtime has not completed bootstrap validation")]
NotBootstrapped,
#[error(transparent)]
Registry(#[from] StaticMemoryDeclarationError),
#[error(transparent)]
State(#[from] RuntimeStateError),
#[error(transparent)]
LedgerCommit(#[from] LedgerCommitError),
#[error(transparent)]
StableCellLedger(#[from] StableCellLedgerError),
#[error(transparent)]
MemoryManagerSlot(#[from] MemoryManagerSlotError),
}
#[non_exhaustive]
#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
pub enum RuntimePolicyError<P> {
#[error(transparent)]
Range(#[from] MemoryManagerRangeAuthorityError),
#[error("runtime declaration metadata is missing for stable key '{0}'")]
MissingDeclarationMetadata(String),
#[error("stable key '{stable_key}' is reserved to authority '{expected_authority}'")]
ReservedStableKeyAuthority {
stable_key: String,
expected_authority: &'static str,
},
#[error(transparent)]
Custom(P),
}