use crate::{
LedgerCommitError, PolicyIdentity, PolicyIdentityError, StableCellLedgerError,
registry::StaticMemoryDeclarationError, slot::MemoryManagerRangeAuthorityError,
};
#[non_exhaustive]
#[derive(Clone, Copy, Debug, Eq, thiserror::Error, PartialEq)]
pub enum RuntimeGrowError {
#[error("virtual memory page count overflows")]
ArithmeticOverflow,
#[error("growth requires {required_buckets} buckets, exceeding capacity {capacity}")]
BucketExhausted {
required_buckets: u64,
capacity: u16,
},
#[error("backing memory refused growth by {additional_pages} pages")]
BackingRefused { additional_pages: u64 },
#[error("runtime memory growth is already in progress")]
ReentrantAccess,
#[error("memory manager refused preflighted growth")]
ManagerRefused,
}
#[non_exhaustive]
#[derive(Clone, Copy, Debug, Eq, thiserror::Error, PartialEq)]
pub enum RuntimeConstructionError {
#[error(transparent)]
Growth(#[from] RuntimeGrowError),
#[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,
}
#[non_exhaustive]
#[derive(Debug, thiserror::Error)]
pub enum RuntimeBootstrapError<P> {
#[error(transparent)]
Admission(#[from] super::BootstrapAdmissionError),
#[error("bootstrap admission policy rejected recovered allocation metadata")]
AdmissionPolicy(P),
#[error(transparent)]
Resolution(#[from] MemoryResolutionError),
#[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)]
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)]
LedgerGrowth(#[from] RuntimeGrowError),
#[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(
"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("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),
}
#[non_exhaustive]
#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
pub enum RuntimePolicyError<P> {
#[error(transparent)]
Range(#[from] MemoryManagerRangeAuthorityError),
#[error(transparent)]
Custom(P),
}
#[non_exhaustive]
#[derive(Debug, thiserror::Error)]
pub enum MemoryResolutionError {
#[error("no eligible free slot for {stable_key} under authority {authority}")]
Exhausted {
stable_key: crate::StableKey,
authority: String,
},
#[error(transparent)]
Range(#[from] crate::MemoryManagerRangeAuthorityError),
#[error(transparent)]
Registry(#[from] StaticMemoryDeclarationError),
}