ic_memory/runtime/
error.rs1use 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 PolicyIdentity(#[from] PolicyIdentityError),
83 #[error("runtime bootstrap declaration snapshot differs from the established binding")]
85 DeclarationSnapshotMismatch,
86 #[error("runtime bootstrap policy identity changed from {established:?} to {requested:?}")]
88 PolicyIdentityMismatch {
89 established: PolicyIdentity,
91 requested: PolicyIdentity,
93 },
94 #[error(transparent)]
96 Registry(#[from] StaticMemoryDeclarationError),
97 #[error(transparent)]
99 LedgerIntegrity(#[from] crate::LedgerIntegrityError),
100 #[error(transparent)]
102 LedgerCommit(#[from] crate::LedgerCommitError),
103 #[error(transparent)]
105 StableCellLedger(#[from] StableCellLedgerError),
106 #[error("stable-cell ledger record size {value_size} cannot be written to stable memory")]
108 StableCellLedgerWriteTooLarge {
109 value_size: usize,
111 },
112 #[error(transparent)]
114 Validation(#[from] crate::AllocationValidationError<RuntimePolicyError<P>>),
115 #[error(transparent)]
117 Staging(#[from] crate::AllocationStageError),
118 #[error(transparent)]
120 State(#[from] RuntimeStateError),
121}
122
123#[non_exhaustive]
130#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
131pub enum RuntimeOpenError {
132 #[error("ic-memory runtime has not completed bootstrap validation")]
134 NotBootstrapped,
135 #[error(transparent)]
137 State(#[from] RuntimeStateError),
138 #[error(transparent)]
140 StableKey(#[from] crate::StableKeyError),
141 #[error("stable key '{0}' was not committed by ic-memory runtime bootstrap")]
143 StableKeyNotCommitted(String),
144 #[error("stable key '{stable_key}' is reserved for ic-memory runtime governance")]
146 ReservedStableKey {
147 stable_key: String,
149 },
150 #[error(transparent)]
152 MemoryManagerSlot(#[from] MemoryManagerSlotError),
153 #[error(
155 "stable key '{stable_key}' is committed for MemoryManager ID {committed_id}, not requested ID {requested_id}"
156 )]
157 MemoryIdMismatch {
158 stable_key: String,
160 committed_id: u8,
162 requested_id: u8,
164 },
165}
166
167#[non_exhaustive]
174#[derive(Debug, thiserror::Error)]
175pub enum RuntimeDiagnosticError {
176 #[error(transparent)]
178 Construction(#[from] RuntimeConstructionError),
179 #[error("allocation bindings exceed the bounded manager domain")]
181 AllocationBound,
182 #[error("ic-memory runtime has not completed bootstrap validation")]
184 NotBootstrapped,
185 #[error(transparent)]
187 Registry(#[from] StaticMemoryDeclarationError),
188 #[error(transparent)]
190 State(#[from] RuntimeStateError),
191 #[error(transparent)]
193 LedgerCommit(#[from] LedgerCommitError),
194 #[error(transparent)]
196 StableCellLedger(#[from] StableCellLedgerError),
197 #[error(transparent)]
199 MemoryManagerSlot(#[from] MemoryManagerSlotError),
200}
201
202#[non_exhaustive]
209#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
210pub enum RuntimePolicyError<P> {
211 #[error(transparent)]
213 Range(#[from] MemoryManagerRangeAuthorityError),
214 #[error("runtime declaration metadata is missing for stable key '{0}'")]
216 MissingDeclarationMetadata(String),
217 #[error("stable key '{stable_key}' is reserved to authority '{expected_authority}'")]
219 ReservedStableKeyAuthority {
220 stable_key: String,
222 expected_authority: &'static str,
224 },
225 #[error(transparent)]
227 Custom(P),
228}