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