1use crate::{
2 LedgerCommitError, PolicyIdentity, PolicyIdentityError, StableCellLedgerError,
3 registry::StaticMemoryDeclarationError, slot::MemoryManagerRangeAuthorityError,
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 #[error("memory manager refused preflighted growth")]
34 ManagerRefused,
35}
36
37#[non_exhaustive]
45#[derive(Clone, Copy, Debug, Eq, thiserror::Error, PartialEq)]
46pub enum RuntimeConstructionError {
47 #[error(transparent)]
49 Growth(#[from] RuntimeGrowError),
50 #[error("bucket size must be nonzero")]
52 InvalidBucketSize,
53 #[error("persisted bucket size {persisted} pages differs from requested {requested}")]
55 BucketSizeMismatch { persisted: u16, requested: u16 },
56 #[error(transparent)]
58 Layout(#[from] super::MemoryManagerLayoutError),
59 #[error(
61 "nonempty backing memory is not an ic-stable-structures MemoryManager \
62 (expected magic 'MGR', found bytes {observed_magic:?})"
63 )]
64 ForeignMemory {
65 observed_magic: [u8; 3],
67 },
68 #[error(
70 "unsupported ic-stable-structures MemoryManager layout version {observed}; \
71 expected {supported}"
72 )]
73 UnsupportedMemoryManagerVersion {
74 observed: u8,
76 supported: u8,
78 },
79}
80
81#[non_exhaustive]
88#[derive(Clone, Copy, Debug, Eq, thiserror::Error, PartialEq)]
89pub enum RuntimeStateError {
90 #[error(transparent)]
92 Construction(#[from] RuntimeConstructionError),
93 #[error("ic-memory default runtime is already borrowed by an active operation")]
95 ReentrantAccess,
96 #[error("ic-memory default runtime is unavailable during thread-local destruction")]
98 Unavailable,
99}
100
101#[non_exhaustive]
108#[derive(Debug, thiserror::Error)]
109pub enum RuntimeBootstrapError<P> {
110 #[error(transparent)]
112 Admission(#[from] super::BootstrapAdmissionError),
113 #[error("bootstrap admission policy rejected recovered allocation metadata")]
115 AdmissionPolicy(P),
116 #[error(transparent)]
117 Resolution(#[from] MemoryResolutionError),
118 #[error(transparent)]
120 PolicyIdentity(#[from] PolicyIdentityError),
121 #[error("runtime bootstrap declaration snapshot differs from the established binding")]
123 DeclarationSnapshotMismatch,
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<RuntimePolicyError<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 #[error(
190 "stable key '{stable_key}' is committed for MemoryManager ID {committed_id}, not requested ID {requested_id}"
191 )]
192 MemoryIdMismatch {
193 stable_key: String,
195 committed_id: u8,
197 requested_id: u8,
199 },
200}
201
202#[non_exhaustive]
209#[derive(Debug, thiserror::Error)]
210pub enum RuntimeDiagnosticError {
211 #[error(transparent)]
213 Construction(#[from] RuntimeConstructionError),
214 #[error("ic-memory runtime has not completed bootstrap validation")]
216 NotBootstrapped,
217 #[error(transparent)]
219 Registry(#[from] StaticMemoryDeclarationError),
220 #[error(transparent)]
222 State(#[from] RuntimeStateError),
223 #[error(transparent)]
225 LedgerCommit(#[from] LedgerCommitError),
226 #[error(transparent)]
228 StableCellLedger(#[from] StableCellLedgerError),
229}
230
231#[non_exhaustive]
238#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
239pub enum RuntimePolicyError<P> {
240 #[error(transparent)]
242 Range(#[from] MemoryManagerRangeAuthorityError),
243 #[error(transparent)]
245 Custom(P),
246}
247
248#[non_exhaustive]
255#[derive(Debug, thiserror::Error)]
256pub enum MemoryResolutionError {
257 #[error("no eligible free slot for {stable_key} under authority {authority}")]
258 Exhausted {
259 stable_key: crate::StableKey,
260 authority: String,
261 },
262 #[error(transparent)]
263 Range(#[from] crate::MemoryManagerRangeAuthorityError),
264 #[error(transparent)]
265 Registry(#[from] StaticMemoryDeclarationError),
266}