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 #[error("ic-memory runtime lifecycle is internally inconsistent")]
101 InconsistentLifecycle,
102}
103
104#[non_exhaustive]
111#[derive(Debug, thiserror::Error)]
112pub enum RuntimeBootstrapError<P> {
113 #[error(transparent)]
115 Admission(#[from] super::BootstrapAdmissionError),
116 #[error("bootstrap admission policy rejected recovered allocation metadata")]
118 AdmissionPolicy(P),
119 #[error(transparent)]
120 Resolution(#[from] MemoryResolutionError),
121 #[error(transparent)]
123 PolicyIdentity(#[from] PolicyIdentityError),
124 #[error("runtime bootstrap declaration snapshot differs from the established binding")]
126 DeclarationSnapshotMismatch,
127 #[error("runtime bootstrap policy identity changed from {established:?} to {requested:?}")]
129 PolicyIdentityMismatch {
130 established: PolicyIdentity,
132 requested: PolicyIdentity,
134 },
135 #[error(transparent)]
137 Registry(#[from] StaticMemoryDeclarationError),
138 #[error(transparent)]
140 LedgerCommit(#[from] crate::LedgerCommitError),
141 #[error(transparent)]
143 StableCellLedger(#[from] StableCellLedgerError),
144 #[error("stable-cell ledger record size {value_size} cannot be written to stable memory")]
146 StableCellLedgerWriteTooLarge {
147 value_size: usize,
149 },
150 #[error(transparent)]
152 LedgerGrowth(#[from] RuntimeGrowError),
153 #[error(transparent)]
155 Validation(#[from] crate::AllocationValidationError<RuntimePolicyError<P>>),
156 #[error(transparent)]
158 Staging(#[from] crate::AllocationStageError),
159 #[error(transparent)]
161 State(#[from] RuntimeStateError),
162}
163
164#[non_exhaustive]
171#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
172pub enum RuntimeOpenError {
173 #[error("ic-memory runtime has not completed bootstrap validation")]
175 NotBootstrapped,
176 #[error(transparent)]
178 State(#[from] RuntimeStateError),
179 #[error(transparent)]
181 StableKey(#[from] crate::StableKeyError),
182 #[error("stable key '{0}' was not committed by ic-memory runtime bootstrap")]
184 StableKeyNotCommitted(String),
185 #[error("stable key '{stable_key}' is reserved for ic-memory runtime governance")]
187 ReservedStableKey {
188 stable_key: String,
190 },
191 #[error(
193 "stable key '{stable_key}' is committed for MemoryManager ID {committed_id}, not requested ID {requested_id}"
194 )]
195 MemoryIdMismatch {
196 stable_key: String,
198 committed_id: u8,
200 requested_id: u8,
202 },
203}
204
205#[non_exhaustive]
212#[derive(Debug, thiserror::Error)]
213pub enum RuntimeDiagnosticError {
214 #[error(transparent)]
216 Construction(#[from] RuntimeConstructionError),
217 #[error("ic-memory runtime has not completed bootstrap validation")]
219 NotBootstrapped,
220 #[error(transparent)]
222 Registry(#[from] StaticMemoryDeclarationError),
223 #[error(transparent)]
225 State(#[from] RuntimeStateError),
226 #[error(transparent)]
228 LedgerCommit(#[from] LedgerCommitError),
229 #[error(transparent)]
231 StableCellLedger(#[from] StableCellLedgerError),
232}
233
234#[non_exhaustive]
241#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
242pub enum RuntimePolicyError<P> {
243 #[error(transparent)]
245 Range(#[from] MemoryManagerRangeAuthorityError),
246 #[error(transparent)]
248 Custom(P),
249}
250
251#[non_exhaustive]
258#[derive(Debug, thiserror::Error)]
259pub enum MemoryResolutionError {
260 #[error("no eligible free slot for {stable_key} under authority {authority}")]
261 Exhausted {
262 stable_key: crate::StableKey,
263 authority: String,
264 },
265 #[error(transparent)]
266 Range(#[from] crate::MemoryManagerRangeAuthorityError),
267 #[error(transparent)]
268 Registry(#[from] StaticMemoryDeclarationError),
269 #[error(transparent)]
270 Declaration(#[from] crate::DeclarationSnapshotError),
271}