1use crate::{
2 LedgerCommitError, PolicyIdentity, PolicyIdentityError, StableCellLedgerError,
3 registry::StaticMemoryDeclarationError,
4 slot::{MemoryManagerRangeAuthorityError, MemoryManagerSlotError},
5};
6
7#[non_exhaustive]
16#[derive(Clone, Copy, Debug, Eq, thiserror::Error, PartialEq)]
17pub enum RuntimeGrowError {
18 #[error("virtual memory page count overflows")]
20 ArithmeticOverflow,
21 #[error("growth requires {required_buckets} buckets, exceeding capacity {capacity}")]
23 BucketExhausted {
24 required_buckets: u64,
25 capacity: u16,
26 },
27 #[error("backing memory refused growth by {additional_pages} pages")]
29 BackingRefused { additional_pages: u64 },
30 #[error("runtime memory growth is already in progress")]
32 ReentrantAccess,
33 #[error("memory manager refused preflighted growth")]
35 ManagerRefused,
36}
37
38#[non_exhaustive]
46#[derive(Clone, Copy, Debug, Eq, thiserror::Error, PartialEq)]
47pub enum RuntimeConstructionError {
48 #[error(transparent)]
50 Growth(#[from] RuntimeGrowError),
51 #[error("bucket size must be nonzero")]
53 InvalidBucketSize,
54 #[error("persisted bucket size {persisted} pages differs from requested {requested}")]
56 BucketSizeMismatch { persisted: u16, requested: u16 },
57 #[error(transparent)]
59 Layout(#[from] super::MemoryManagerLayoutError),
60 #[error(
62 "nonempty backing memory is not an ic-stable-structures MemoryManager \
63 (expected magic 'MGR', found bytes {observed_magic:?})"
64 )]
65 ForeignMemory {
66 observed_magic: [u8; 3],
68 },
69 #[error(
71 "unsupported ic-stable-structures MemoryManager layout version {observed}; \
72 expected {supported}"
73 )]
74 UnsupportedMemoryManagerVersion {
75 observed: u8,
77 supported: u8,
79 },
80}
81
82#[non_exhaustive]
89#[derive(Clone, Copy, Debug, Eq, thiserror::Error, PartialEq)]
90pub enum RuntimeStateError {
91 #[error(transparent)]
93 Construction(#[from] RuntimeConstructionError),
94 #[error("ic-memory default runtime is already borrowed by an active operation")]
96 ReentrantAccess,
97 #[error("ic-memory default runtime is unavailable during thread-local destruction")]
99 Unavailable,
100 #[error("ic-memory runtime lifecycle is internally inconsistent")]
102 InconsistentLifecycle,
103}
104
105#[non_exhaustive]
112#[derive(Debug, thiserror::Error)]
113pub enum RuntimeBootstrapError<P> {
114 #[error(transparent)]
116 Admission(#[from] super::BootstrapAdmissionError),
117 #[error("bootstrap admission policy rejected recovered allocation metadata")]
119 AdmissionPolicy(P),
120 #[error(transparent)]
121 Resolution(#[from] MemoryResolutionError),
122 #[error(transparent)]
124 PolicyIdentity(#[from] PolicyIdentityError),
125 #[error("runtime bootstrap declaration snapshot differs from the established binding")]
127 DeclarationSnapshotMismatch,
128 #[error("runtime bootstrap policy identity changed from {established:?} to {requested:?}")]
130 PolicyIdentityMismatch {
131 established: PolicyIdentity,
133 requested: PolicyIdentity,
135 },
136 #[error(transparent)]
138 Registry(#[from] StaticMemoryDeclarationError),
139 #[error(transparent)]
141 LedgerIntegrity(#[from] crate::LedgerIntegrityError),
142 #[error(transparent)]
144 LedgerCommit(#[from] crate::LedgerCommitError),
145 #[error(transparent)]
147 StableCellLedger(#[from] StableCellLedgerError),
148 #[error("stable-cell ledger record size {value_size} cannot be written to stable memory")]
150 StableCellLedgerWriteTooLarge {
151 value_size: usize,
153 },
154 #[error(transparent)]
156 LedgerGrowth(#[from] RuntimeGrowError),
157 #[error(transparent)]
159 Validation(#[from] crate::AllocationValidationError<RuntimePolicyError<P>>),
160 #[error(transparent)]
162 Staging(#[from] crate::AllocationStageError),
163 #[error(transparent)]
165 State(#[from] RuntimeStateError),
166}
167
168#[non_exhaustive]
175#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
176pub enum RuntimeOpenError {
177 #[error("ic-memory runtime has not completed bootstrap validation")]
179 NotBootstrapped,
180 #[error(transparent)]
182 State(#[from] RuntimeStateError),
183 #[error(transparent)]
185 StableKey(#[from] crate::StableKeyError),
186 #[error("stable key '{0}' was not committed by ic-memory runtime bootstrap")]
188 StableKeyNotCommitted(String),
189 #[error("stable key '{stable_key}' is reserved for ic-memory runtime governance")]
191 ReservedStableKey {
192 stable_key: String,
194 },
195 #[error(transparent)]
197 MemoryManagerSlot(#[from] MemoryManagerSlotError),
198 #[error(
200 "stable key '{stable_key}' is committed for MemoryManager ID {committed_id}, not requested ID {requested_id}"
201 )]
202 MemoryIdMismatch {
203 stable_key: String,
205 committed_id: u8,
207 requested_id: u8,
209 },
210}
211
212#[non_exhaustive]
219#[derive(Debug, thiserror::Error)]
220pub enum RuntimeDiagnosticError {
221 #[error(transparent)]
223 Construction(#[from] RuntimeConstructionError),
224 #[error("allocation bindings exceed the bounded manager domain")]
226 AllocationBound,
227 #[error("ic-memory runtime has not completed bootstrap validation")]
229 NotBootstrapped,
230 #[error(transparent)]
232 Registry(#[from] StaticMemoryDeclarationError),
233 #[error(transparent)]
235 State(#[from] RuntimeStateError),
236 #[error(transparent)]
238 LedgerCommit(#[from] LedgerCommitError),
239 #[error(transparent)]
241 StableCellLedger(#[from] StableCellLedgerError),
242 #[error(transparent)]
244 MemoryManagerSlot(#[from] MemoryManagerSlotError),
245}
246
247#[non_exhaustive]
254#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
255pub enum RuntimePolicyError<P> {
256 #[error(transparent)]
258 Range(#[from] MemoryManagerRangeAuthorityError),
259 #[error("runtime declaration metadata is missing for stable key '{0}'")]
261 MissingDeclarationMetadata(String),
262 #[error(transparent)]
264 Custom(P),
265}
266
267#[non_exhaustive]
274#[derive(Debug, thiserror::Error)]
275pub enum MemoryResolutionError {
276 #[error("no eligible free slot for {stable_key} under authority {authority}")]
277 Exhausted {
278 stable_key: crate::StableKey,
279 authority: String,
280 },
281 #[error(transparent)]
282 Range(#[from] crate::MemoryManagerRangeAuthorityError),
283 #[error(transparent)]
284 Registry(#[from] StaticMemoryDeclarationError),
285 #[error(transparent)]
286 Declaration(#[from] crate::DeclarationSnapshotError),
287}