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("bucket size must be nonzero")]
50 InvalidBucketSize,
51 #[error("persisted bucket size {persisted} pages differs from requested {requested}")]
53 BucketSizeMismatch { persisted: u16, requested: u16 },
54 #[error(transparent)]
56 Layout(#[from] super::MemoryManagerLayoutError),
57 #[error(
59 "nonempty backing memory is not an ic-stable-structures MemoryManager \
60 (expected magic 'MGR', found bytes {observed_magic:?})"
61 )]
62 ForeignMemory {
63 observed_magic: [u8; 3],
65 },
66 #[error(
68 "unsupported ic-stable-structures MemoryManager layout version {observed}; \
69 expected {supported}"
70 )]
71 UnsupportedMemoryManagerVersion {
72 observed: u8,
74 supported: u8,
76 },
77}
78
79#[non_exhaustive]
86#[derive(Clone, Copy, Debug, Eq, thiserror::Error, PartialEq)]
87pub enum RuntimeStateError {
88 #[error(transparent)]
90 Construction(#[from] RuntimeConstructionError),
91 #[error("ic-memory default runtime is already borrowed by an active operation")]
93 ReentrantAccess,
94 #[error("ic-memory default runtime is unavailable during thread-local destruction")]
96 Unavailable,
97 #[error("ic-memory runtime lifecycle is internally inconsistent")]
99 InconsistentLifecycle,
100}
101
102#[non_exhaustive]
109#[derive(Debug, thiserror::Error)]
110pub enum RuntimeBootstrapError<P> {
111 #[error(transparent)]
113 Admission(#[from] super::BootstrapAdmissionError),
114 #[error("bootstrap admission policy rejected recovered allocation metadata")]
116 AdmissionPolicy(P),
117 #[error(transparent)]
118 Resolution(#[from] MemoryResolutionError),
119 #[error(transparent)]
121 PolicyIdentity(#[from] PolicyIdentityError),
122 #[error("runtime bootstrap declaration snapshot differs from the established binding")]
124 DeclarationSnapshotMismatch,
125 #[error("runtime bootstrap policy identity changed from {established:?} to {requested:?}")]
127 PolicyIdentityMismatch {
128 established: PolicyIdentity,
130 requested: PolicyIdentity,
132 },
133 #[error(transparent)]
135 Registry(#[from] StaticMemoryDeclarationError),
136 #[error(transparent)]
138 LedgerIntegrity(#[from] crate::LedgerIntegrityError),
139 #[error(transparent)]
141 LedgerCommit(#[from] crate::LedgerCommitError),
142 #[error(transparent)]
144 StableCellLedger(#[from] StableCellLedgerError),
145 #[error("stable-cell ledger record size {value_size} cannot be written to stable memory")]
147 StableCellLedgerWriteTooLarge {
148 value_size: usize,
150 },
151 #[error(transparent)]
153 LedgerGrowth(#[from] RuntimeGrowError),
154 #[error(transparent)]
156 Validation(#[from] crate::AllocationValidationError<RuntimePolicyError<P>>),
157 #[error(transparent)]
159 Staging(#[from] crate::AllocationStageError),
160 #[error(transparent)]
162 State(#[from] RuntimeStateError),
163}
164
165#[non_exhaustive]
172#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
173pub enum RuntimeOpenError {
174 #[error("ic-memory runtime has not completed bootstrap validation")]
176 NotBootstrapped,
177 #[error(transparent)]
179 State(#[from] RuntimeStateError),
180 #[error(transparent)]
182 StableKey(#[from] crate::StableKeyError),
183 #[error("stable key '{0}' was not committed by ic-memory runtime bootstrap")]
185 StableKeyNotCommitted(String),
186 #[error("stable key '{stable_key}' is reserved for ic-memory runtime governance")]
188 ReservedStableKey {
189 stable_key: String,
191 },
192 #[error(transparent)]
194 MemoryManagerSlot(#[from] MemoryManagerSlotError),
195 #[error(
197 "stable key '{stable_key}' is committed for MemoryManager ID {committed_id}, not requested ID {requested_id}"
198 )]
199 MemoryIdMismatch {
200 stable_key: String,
202 committed_id: u8,
204 requested_id: u8,
206 },
207}
208
209#[non_exhaustive]
216#[derive(Debug, thiserror::Error)]
217pub enum RuntimeDiagnosticError {
218 #[error(transparent)]
220 Construction(#[from] RuntimeConstructionError),
221 #[error("allocation bindings exceed the bounded manager domain")]
223 AllocationBound,
224 #[error("ic-memory runtime has not completed bootstrap validation")]
226 NotBootstrapped,
227 #[error(transparent)]
229 Registry(#[from] StaticMemoryDeclarationError),
230 #[error(transparent)]
232 State(#[from] RuntimeStateError),
233 #[error(transparent)]
235 LedgerCommit(#[from] LedgerCommitError),
236 #[error(transparent)]
238 StableCellLedger(#[from] StableCellLedgerError),
239 #[error(transparent)]
241 MemoryManagerSlot(#[from] MemoryManagerSlotError),
242}
243
244#[non_exhaustive]
251#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
252pub enum RuntimePolicyError<P> {
253 #[error(transparent)]
255 Range(#[from] MemoryManagerRangeAuthorityError),
256 #[error("runtime declaration metadata is missing for stable key '{0}'")]
258 MissingDeclarationMetadata(String),
259 #[error("stable key '{stable_key}' is reserved to authority '{expected_authority}'")]
261 ReservedStableKeyAuthority {
262 stable_key: String,
264 expected_authority: &'static str,
266 },
267 #[error(transparent)]
269 Custom(P),
270}
271
272#[non_exhaustive]
279#[derive(Debug, thiserror::Error)]
280pub enum MemoryResolutionError {
281 #[error("no eligible free slot for {stable_key} under authority {authority}")]
282 Exhausted {
283 stable_key: crate::StableKey,
284 authority: String,
285 },
286 #[error(transparent)]
287 Range(#[from] crate::MemoryManagerRangeAuthorityError),
288 #[error(transparent)]
289 Registry(#[from] StaticMemoryDeclarationError),
290 #[error(transparent)]
291 Declaration(#[from] crate::DeclarationSnapshotError),
292}