ic_memory/runtime/
error.rs1use crate::{
2 LedgerCommitError, PolicyIdentity, PolicyIdentityError, StableCellLedgerError,
3 registry::StaticMemoryDeclarationError,
4};
5
6#[non_exhaustive]
15#[derive(Clone, Copy, Debug, Eq, thiserror::Error, PartialEq)]
16pub enum RuntimeGrowError {
17 #[error("virtual memory page count overflows")]
19 ArithmeticOverflow,
20 #[error("growth requires {required_buckets} buckets, exceeding capacity {capacity}")]
22 BucketExhausted {
23 required_buckets: u64,
24 capacity: u16,
25 },
26 #[error("backing memory refused growth by {additional_pages} pages")]
28 BackingRefused { additional_pages: u64 },
29 #[error("runtime memory growth is already in progress")]
31 ReentrantAccess,
32}
33
34#[non_exhaustive]
42#[derive(Clone, Copy, Debug, Eq, thiserror::Error, PartialEq)]
43pub enum RuntimeConstructionError {
44 #[error(transparent)]
46 Growth(#[from] RuntimeGrowError),
47 #[error("bucket size must be nonzero")]
49 InvalidBucketSize,
50 #[error("persisted bucket size {persisted} pages differs from requested {requested}")]
52 BucketSizeMismatch { persisted: u16, requested: u16 },
53 #[error(transparent)]
55 Layout(#[from] super::MemoryManagerLayoutError),
56 #[error(
58 "nonempty backing memory is not an ic-stable-structures MemoryManager \
59 (expected magic 'MGR', found bytes {observed_magic:?})"
60 )]
61 ForeignMemory {
62 observed_magic: [u8; 3],
64 },
65 #[error(
67 "unsupported ic-stable-structures MemoryManager layout version {observed}; \
68 expected {supported}"
69 )]
70 UnsupportedMemoryManagerVersion {
71 observed: u8,
73 supported: u8,
75 },
76}
77
78#[non_exhaustive]
85#[derive(Clone, Copy, Debug, Eq, thiserror::Error, PartialEq)]
86pub enum RuntimeStateError {
87 #[error(transparent)]
89 Construction(#[from] RuntimeConstructionError),
90 #[error("ic-memory default runtime is already borrowed by an active operation")]
92 ReentrantAccess,
93 #[error("ic-memory default runtime is unavailable during thread-local destruction")]
95 Unavailable,
96}
97
98#[non_exhaustive]
105#[derive(Debug, thiserror::Error)]
106pub enum RuntimeBootstrapError<P> {
107 #[error(transparent)]
109 Admission(#[from] super::BootstrapAdmissionError),
110 #[error("bootstrap admission policy rejected recovered allocation metadata")]
112 AdmissionPolicy(P),
113 #[error(transparent)]
114 Resolution(#[from] MemoryResolutionError),
115 #[error(transparent)]
117 PolicyIdentity(#[from] PolicyIdentityError),
118 #[error("runtime bootstrap declaration snapshot differs from the established binding")]
120 DeclarationSnapshotMismatch,
121 #[error("runtime allocation pool differs from the established host policy")]
123 AllocationPoolMismatch,
124 #[error("runtime bootstrap policy identity changed from {established:?} to {requested:?}")]
126 PolicyIdentityMismatch {
127 established: PolicyIdentity,
129 requested: PolicyIdentity,
131 },
132 #[error(transparent)]
134 Registry(#[from] StaticMemoryDeclarationError),
135 #[error(transparent)]
137 LedgerCommit(#[from] crate::LedgerCommitError),
138 #[error(transparent)]
140 StableCellLedger(#[from] StableCellLedgerError),
141 #[error("stable-cell ledger record size {value_size} cannot be written to stable memory")]
143 StableCellLedgerWriteTooLarge {
144 value_size: usize,
146 },
147 #[error(transparent)]
149 LedgerGrowth(#[from] RuntimeGrowError),
150 #[error(transparent)]
152 Validation(#[from] crate::AllocationValidationError<P>),
153 #[error(transparent)]
155 Staging(#[from] crate::AllocationStageError),
156 #[error(transparent)]
158 State(#[from] RuntimeStateError),
159}
160
161#[non_exhaustive]
168#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
169pub enum RuntimeOpenError {
170 #[error("ic-memory runtime has not completed bootstrap validation")]
172 NotBootstrapped,
173 #[error(transparent)]
175 State(#[from] RuntimeStateError),
176 #[error(transparent)]
178 StableKey(#[from] crate::StableKeyError),
179 #[error("stable key '{0}' was not committed by ic-memory runtime bootstrap")]
181 StableKeyNotCommitted(String),
182 #[error("stable key '{stable_key}' is reserved for ic-memory runtime governance")]
184 ReservedStableKey {
185 stable_key: String,
187 },
188}
189
190#[non_exhaustive]
197#[derive(Debug, thiserror::Error)]
198pub enum RuntimeDiagnosticError {
199 #[error(transparent)]
201 Construction(#[from] RuntimeConstructionError),
202 #[error("ic-memory runtime has not completed bootstrap validation")]
204 NotBootstrapped,
205 #[error(transparent)]
207 Registry(#[from] StaticMemoryDeclarationError),
208 #[error(transparent)]
210 State(#[from] RuntimeStateError),
211 #[error(transparent)]
213 LedgerCommit(#[from] LedgerCommitError),
214 #[error(transparent)]
216 StableCellLedger(#[from] StableCellLedgerError),
217}
218
219#[non_exhaustive]
226#[derive(Debug, thiserror::Error)]
227pub enum MemoryResolutionError {
228 #[error("unmanaged MemoryManager ID {id} needs an explicit host exclusion")]
230 UnmanagedAllocation { id: u8 },
231 #[error("no eligible free slot for {stable_key} under authority {authority}")]
232 Exhausted {
233 stable_key: crate::StableKey,
234 authority: String,
235 },
236 #[error(transparent)]
237 Pool(#[from] crate::MemoryAllocationPoolError),
238 #[error(transparent)]
239 Registry(#[from] StaticMemoryDeclarationError),
240}