miden_client/store/
errors.rs1use alloc::string::String;
2use core::num::TryFromIntError;
3
4use miden_protocol::account::AccountId;
5use miden_protocol::asset::AssetId;
6use miden_protocol::block::BlockNumber;
7use miden_protocol::crypto::merkle::MerkleError;
8use miden_protocol::crypto::merkle::mmr::MmrError;
9use miden_protocol::crypto::merkle::smt::SmtProofError;
10use miden_protocol::errors::{
11 AccountDeltaError,
12 AccountError,
13 AccountIdError,
14 AccountPatchError,
15 AddressError,
16 AssetError,
17 AssetVaultError,
18 NoteError,
19 StorageMapError,
20};
21use miden_protocol::utils::HexParseError;
22use miden_protocol::utils::serde::DeserializationError;
23use miden_protocol::{MastForestScriptError, Word, WordError};
24use miden_tx::DataStoreError;
25use thiserror::Error;
26
27use super::note_record::NoteRecordError;
28
29#[derive(Debug, Error)]
34#[allow(clippy::large_enum_variant)]
35pub enum StoreError {
36 #[error(
37 "protocol configuration {0} is not stored; register it with Client::add_protocol_config"
38 )]
39 ProtocolConfigNotFound(Word),
40 #[error("stored protocol configuration does not match commitment {0}")]
41 ProtocolConfigCommitmentMismatch(Word),
42 #[error("asset error")]
43 AssetError(#[from] AssetError),
44 #[error("asset vault error")]
45 AssetVaultError(#[from] AssetVaultError),
46 #[error("account code data with root {0} not found")]
47 AccountCodeDataNotFound(Word),
48 #[error("account data wasn't found for account id {0}")]
49 AccountDataNotFound(AccountId),
50 #[error("account delta error")]
51 AccountDeltaError(#[from] AccountDeltaError),
52 #[error("account patch error")]
53 AccountPatchError(#[from] AccountPatchError),
54 #[error("account error")]
55 AccountError(#[from] AccountError),
56 #[error("address error")]
57 AddressError(#[from] AddressError),
58 #[error("invalid account ID")]
59 AccountIdError(#[from] AccountIdError),
60 #[error("stored account commitment does not match the expected commitment for account {0}")]
61 AccountCommitmentMismatch(AccountId),
62 #[error("account storage data with root {0} not found")]
63 AccountStorageRootNotFound(Word),
64 #[error("account storage data with index {0} not found")]
65 AccountStorageIndexNotFound(usize),
66 #[error("block header for block {0} not found")]
67 BlockHeaderNotFound(BlockNumber),
68 #[error("partial blockchain node at index {0} not found")]
69 PartialBlockchainNodeNotFound(u64),
70 #[error("failed to deserialize data from the store")]
71 DataDeserializationError(#[from] DeserializationError),
72 #[error("database-related non-query error: {0}")]
73 DatabaseError(String),
74 #[error("transient database error, the operation can be retried: {0}")]
75 DatabaseTransientError(String),
76 #[error("permanent database error: {0}")]
77 DatabasePermanentError(String),
78 #[error("failed to parse hex value")]
79 HexParseError(#[from] HexParseError),
80 #[error("integer conversion failed")]
81 InvalidInt(#[from] TryFromIntError),
82 #[error("note record error")]
83 NoteRecordError(#[from] NoteRecordError),
84 #[error("merkle store error")]
85 MerkleStoreError(#[from] MerkleError),
86 #[error("failed to construct Merkle Mountain Range (MMR)")]
87 MmrError(#[from] MmrError),
88 #[error("failed to create note inclusion proof")]
89 NoteInclusionProofError(#[from] NoteError),
90 #[error("note tag {0} is already being tracked")]
91 NoteTagAlreadyTracked(u64),
92 #[error("note script with root {0} not found")]
93 NoteScriptNotFound(String),
94 #[error("failed to parse data retrieved from the database: {0}")]
95 ParsingError(String),
96 #[error("failed to retrieve data from the database: {0}")]
97 QueryError(String),
98 #[error("sparse merkle tree proof error")]
99 SmtProofError(#[from] SmtProofError),
100 #[error("account storage map error")]
101 StorageMapError(#[from] StorageMapError),
102 #[error("failed to instantiate a script from its mast forest")]
103 MastForestScriptError(#[from] MastForestScriptError),
104 #[error("account vault data for root {0} not found")]
105 VaultDataNotFound(Word),
106 #[error("vault key {0:?} (hashed to {1}) is not tracked in the vault")]
107 VaultKeyNotTracked(AssetId, Word),
108 #[error("failed to parse word")]
109 WordError(#[from] WordError),
110}
111
112impl From<StoreError> for DataStoreError {
113 fn from(value: StoreError) -> Self {
114 match value {
115 StoreError::AccountDataNotFound(account_id) => {
116 DataStoreError::AccountNotFound(account_id)
117 },
118 err => DataStoreError::other_with_source("store error", err),
119 }
120 }
121}