1use crate::{
2 LedgerCommitError, PolicyIdentity, PolicyIdentityError, StableCellLedgerError,
3 registry::StaticMemoryDeclarationError,
4 slot::{MemoryManagerRangeAuthorityError, MemoryManagerSlotError},
5};
6
7#[non_exhaustive]
15#[derive(Clone, Copy, Debug, Eq, thiserror::Error, PartialEq)]
16pub enum RuntimeConstructionError {
17 #[error("bucket size must be nonzero")]
19 InvalidBucketSize,
20 #[error("persisted bucket size {persisted} pages differs from requested {requested}")]
22 BucketSizeMismatch { persisted: u16, requested: u16 },
23 #[error(transparent)]
25 Layout(#[from] super::MemoryManagerLayoutError),
26 #[error(
28 "nonempty backing memory is not an ic-stable-structures MemoryManager \
29 (expected magic 'MGR', found bytes {observed_magic:?})"
30 )]
31 ForeignMemory {
32 observed_magic: [u8; 3],
34 },
35 #[error(
37 "unsupported ic-stable-structures MemoryManager layout version {observed}; \
38 expected {supported}"
39 )]
40 UnsupportedMemoryManagerVersion {
41 observed: u8,
43 supported: u8,
45 },
46}
47
48#[non_exhaustive]
55#[derive(Clone, Copy, Debug, Eq, thiserror::Error, PartialEq)]
56pub enum RuntimeStateError {
57 #[error(transparent)]
59 Construction(#[from] RuntimeConstructionError),
60 #[error("ic-memory default runtime is already borrowed by an active operation")]
62 ReentrantAccess,
63 #[error("ic-memory default runtime is unavailable during thread-local destruction")]
65 Unavailable,
66 #[error("ic-memory runtime lifecycle is internally inconsistent")]
68 InconsistentLifecycle,
69}
70
71#[non_exhaustive]
78#[derive(Debug, thiserror::Error)]
79pub enum RuntimeBootstrapError<P> {
80 #[error(transparent)]
82 Admission(#[from] super::BootstrapAdmissionError),
83 #[error("bootstrap admission policy rejected recovered allocation metadata")]
85 AdmissionPolicy(P),
86 #[error(transparent)]
87 Resolution(#[from] MemoryResolutionError),
88 #[error(transparent)]
90 PolicyIdentity(#[from] PolicyIdentityError),
91 #[error("runtime bootstrap declaration snapshot differs from the established binding")]
93 DeclarationSnapshotMismatch,
94 #[error("runtime bootstrap policy identity changed from {established:?} to {requested:?}")]
96 PolicyIdentityMismatch {
97 established: PolicyIdentity,
99 requested: PolicyIdentity,
101 },
102 #[error(transparent)]
104 Registry(#[from] StaticMemoryDeclarationError),
105 #[error(transparent)]
107 LedgerIntegrity(#[from] crate::LedgerIntegrityError),
108 #[error(transparent)]
110 LedgerCommit(#[from] crate::LedgerCommitError),
111 #[error(transparent)]
113 StableCellLedger(#[from] StableCellLedgerError),
114 #[error("stable-cell ledger record size {value_size} cannot be written to stable memory")]
116 StableCellLedgerWriteTooLarge {
117 value_size: usize,
119 },
120 #[error(transparent)]
122 Validation(#[from] crate::AllocationValidationError<RuntimePolicyError<P>>),
123 #[error(transparent)]
125 Staging(#[from] crate::AllocationStageError),
126 #[error(transparent)]
128 State(#[from] RuntimeStateError),
129}
130
131#[non_exhaustive]
138#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
139pub enum RuntimeOpenError {
140 #[error("ic-memory runtime has not completed bootstrap validation")]
142 NotBootstrapped,
143 #[error(transparent)]
145 State(#[from] RuntimeStateError),
146 #[error(transparent)]
148 StableKey(#[from] crate::StableKeyError),
149 #[error("stable key '{0}' was not committed by ic-memory runtime bootstrap")]
151 StableKeyNotCommitted(String),
152 #[error("stable key '{stable_key}' is reserved for ic-memory runtime governance")]
154 ReservedStableKey {
155 stable_key: String,
157 },
158 #[error(transparent)]
160 MemoryManagerSlot(#[from] MemoryManagerSlotError),
161 #[error(
163 "stable key '{stable_key}' is committed for MemoryManager ID {committed_id}, not requested ID {requested_id}"
164 )]
165 MemoryIdMismatch {
166 stable_key: String,
168 committed_id: u8,
170 requested_id: u8,
172 },
173}
174
175#[non_exhaustive]
182#[derive(Debug, thiserror::Error)]
183pub enum RuntimeDiagnosticError {
184 #[error(transparent)]
186 Construction(#[from] RuntimeConstructionError),
187 #[error("allocation bindings exceed the bounded manager domain")]
189 AllocationBound,
190 #[error("ic-memory runtime has not completed bootstrap validation")]
192 NotBootstrapped,
193 #[error(transparent)]
195 Registry(#[from] StaticMemoryDeclarationError),
196 #[error(transparent)]
198 State(#[from] RuntimeStateError),
199 #[error(transparent)]
201 LedgerCommit(#[from] LedgerCommitError),
202 #[error(transparent)]
204 StableCellLedger(#[from] StableCellLedgerError),
205 #[error(transparent)]
207 MemoryManagerSlot(#[from] MemoryManagerSlotError),
208}
209
210#[non_exhaustive]
217#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
218pub enum RuntimePolicyError<P> {
219 #[error(transparent)]
221 Range(#[from] MemoryManagerRangeAuthorityError),
222 #[error("runtime declaration metadata is missing for stable key '{0}'")]
224 MissingDeclarationMetadata(String),
225 #[error("stable key '{stable_key}' is reserved to authority '{expected_authority}'")]
227 ReservedStableKeyAuthority {
228 stable_key: String,
230 expected_authority: &'static str,
232 },
233 #[error(transparent)]
235 Custom(P),
236}
237
238#[non_exhaustive]
245#[derive(Debug, thiserror::Error)]
246pub enum MemoryResolutionError {
247 #[error("no eligible free slot for {stable_key} under authority {authority}")]
248 Exhausted {
249 stable_key: crate::StableKey,
250 authority: String,
251 },
252 #[error(transparent)]
253 Range(#[from] crate::MemoryManagerRangeAuthorityError),
254 #[error(transparent)]
255 Registry(#[from] StaticMemoryDeclarationError),
256 #[error(transparent)]
257 Declaration(#[from] crate::DeclarationSnapshotError),
258}