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