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 LedgerIntegrity(#[from] crate::LedgerIntegrityError),
141 #[error(transparent)]
143 LedgerCommit(#[from] crate::LedgerCommitError),
144 #[error(transparent)]
146 StableCellLedger(#[from] StableCellLedgerError),
147 #[error("stable-cell ledger record size {value_size} cannot be written to stable memory")]
149 StableCellLedgerWriteTooLarge {
150 value_size: usize,
152 },
153 #[error(transparent)]
155 LedgerGrowth(#[from] RuntimeGrowError),
156 #[error(transparent)]
158 Validation(#[from] crate::AllocationValidationError<RuntimePolicyError<P>>),
159 #[error(transparent)]
161 Staging(#[from] crate::AllocationStageError),
162 #[error(transparent)]
164 State(#[from] RuntimeStateError),
165}
166
167#[non_exhaustive]
174#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
175pub enum RuntimeOpenError {
176 #[error("ic-memory runtime has not completed bootstrap validation")]
178 NotBootstrapped,
179 #[error(transparent)]
181 State(#[from] RuntimeStateError),
182 #[error(transparent)]
184 StableKey(#[from] crate::StableKeyError),
185 #[error("stable key '{0}' was not committed by ic-memory runtime bootstrap")]
187 StableKeyNotCommitted(String),
188 #[error("stable key '{stable_key}' is reserved for ic-memory runtime governance")]
190 ReservedStableKey {
191 stable_key: String,
193 },
194 #[error(
196 "stable key '{stable_key}' is committed for MemoryManager ID {committed_id}, not requested ID {requested_id}"
197 )]
198 MemoryIdMismatch {
199 stable_key: String,
201 committed_id: u8,
203 requested_id: u8,
205 },
206}
207
208#[non_exhaustive]
215#[derive(Debug, thiserror::Error)]
216pub enum RuntimeDiagnosticError {
217 #[error(transparent)]
219 Construction(#[from] RuntimeConstructionError),
220 #[error("ic-memory runtime has not completed bootstrap validation")]
222 NotBootstrapped,
223 #[error(transparent)]
225 Registry(#[from] StaticMemoryDeclarationError),
226 #[error(transparent)]
228 State(#[from] RuntimeStateError),
229 #[error(transparent)]
231 LedgerCommit(#[from] LedgerCommitError),
232 #[error(transparent)]
234 StableCellLedger(#[from] StableCellLedgerError),
235}
236
237#[non_exhaustive]
244#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
245pub enum RuntimePolicyError<P> {
246 #[error(transparent)]
248 Range(#[from] MemoryManagerRangeAuthorityError),
249 #[error("runtime declaration metadata is missing for stable key '{0}'")]
251 MissingDeclarationMetadata(String),
252 #[error(transparent)]
254 Custom(P),
255}
256
257#[non_exhaustive]
264#[derive(Debug, thiserror::Error)]
265pub enum MemoryResolutionError {
266 #[error("no eligible free slot for {stable_key} under authority {authority}")]
267 Exhausted {
268 stable_key: crate::StableKey,
269 authority: String,
270 },
271 #[error(transparent)]
272 Range(#[from] crate::MemoryManagerRangeAuthorityError),
273 #[error(transparent)]
274 Registry(#[from] StaticMemoryDeclarationError),
275 #[error(transparent)]
276 Declaration(#[from] crate::DeclarationSnapshotError),
277}