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