ic_memory/runtime/
error.rs1use crate::{
2 LedgerCommitError, 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(
19 "nonempty backing memory is not an ic-stable-structures MemoryManager \
20 (expected magic 'MGR', found bytes {observed_magic:?})"
21 )]
22 ForeignMemory {
23 observed_magic: [u8; 3],
25 },
26 #[error(
28 "unsupported ic-stable-structures MemoryManager layout version {observed}; \
29 expected {supported}"
30 )]
31 UnsupportedMemoryManagerVersion {
32 observed: u8,
34 supported: u8,
36 },
37}
38
39#[non_exhaustive]
46#[derive(Clone, Copy, Debug, Eq, thiserror::Error, PartialEq)]
47pub enum RuntimeStateError {
48 #[error(transparent)]
50 Construction(#[from] RuntimeConstructionError),
51 #[error("ic-memory default runtime is already borrowed by an active operation")]
53 ReentrantAccess,
54 #[error("ic-memory default runtime is unavailable during thread-local destruction")]
56 Unavailable,
57 #[error("ic-memory runtime lifecycle is internally inconsistent")]
59 InconsistentLifecycle,
60}
61
62#[non_exhaustive]
69#[derive(Debug, thiserror::Error)]
70pub enum RuntimeBootstrapError<P> {
71 #[error("runtime bootstrap policy identity must not be empty")]
73 EmptyPolicyIdentity,
74 #[error("runtime bootstrap declaration snapshot differs from the established binding")]
76 DeclarationSnapshotMismatch,
77 #[error("runtime bootstrap policy identity changed from '{established}' to '{requested}'")]
79 PolicyIdentityMismatch {
80 established: &'static str,
82 requested: &'static str,
84 },
85 #[error(transparent)]
87 Registry(#[from] StaticMemoryDeclarationError),
88 #[error(transparent)]
90 LedgerIntegrity(#[from] crate::LedgerIntegrityError),
91 #[error(transparent)]
93 LedgerCommit(#[from] crate::LedgerCommitError),
94 #[error(transparent)]
96 StableCellLedger(#[from] StableCellLedgerError),
97 #[error("stable-cell ledger record size {value_size} cannot be written to stable memory")]
99 StableCellLedgerWriteTooLarge {
100 value_size: usize,
102 },
103 #[error(transparent)]
105 Validation(#[from] crate::AllocationValidationError<RuntimePolicyError<P>>),
106 #[error(transparent)]
108 Staging(#[from] crate::AllocationStageError),
109 #[error(transparent)]
111 State(#[from] RuntimeStateError),
112}
113
114#[non_exhaustive]
121#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
122pub enum RuntimeOpenError {
123 #[error("ic-memory runtime has not completed bootstrap validation")]
125 NotBootstrapped,
126 #[error(transparent)]
128 State(#[from] RuntimeStateError),
129 #[error(transparent)]
131 StableKey(#[from] crate::StableKeyError),
132 #[error("stable key '{0}' was not committed by ic-memory runtime bootstrap")]
134 StableKeyNotCommitted(String),
135 #[error("stable key '{stable_key}' is reserved for ic-memory runtime governance")]
137 ReservedStableKey {
138 stable_key: String,
140 },
141 #[error(transparent)]
143 MemoryManagerSlot(#[from] MemoryManagerSlotError),
144 #[error(
146 "stable key '{stable_key}' is committed for MemoryManager ID {committed_id}, not requested ID {requested_id}"
147 )]
148 MemoryIdMismatch {
149 stable_key: String,
151 committed_id: u8,
153 requested_id: u8,
155 },
156}
157
158#[non_exhaustive]
165#[derive(Debug, thiserror::Error)]
166pub enum RuntimeDiagnosticError {
167 #[error("ic-memory runtime has not completed bootstrap validation")]
169 NotBootstrapped,
170 #[error(transparent)]
172 Registry(#[from] StaticMemoryDeclarationError),
173 #[error(transparent)]
175 State(#[from] RuntimeStateError),
176 #[error(transparent)]
178 LedgerCommit(#[from] LedgerCommitError),
179 #[error(transparent)]
181 StableCellLedger(#[from] StableCellLedgerError),
182 #[error(transparent)]
184 MemoryManagerSlot(#[from] MemoryManagerSlotError),
185}
186
187#[non_exhaustive]
194#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
195pub enum RuntimePolicyError<P> {
196 #[error(transparent)]
198 Range(#[from] MemoryManagerRangeAuthorityError),
199 #[error("runtime declaration metadata is missing for stable key '{0}'")]
201 MissingDeclarationMetadata(String),
202 #[error("stable key '{stable_key}' is reserved to authority '{expected_authority}'")]
204 ReservedStableKeyAuthority {
205 stable_key: String,
207 expected_authority: &'static str,
209 },
210 #[error(transparent)]
212 Custom(P),
213}