Skip to main content

miden_client/store/
errors.rs

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