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("account id error")]
46    AccountIdError(#[from] AccountIdError),
47    #[error("account commitment mismatch for account {0}")]
48    AccountCommitmentMismatch(AccountId),
49    #[error("public key {0} not found")]
50    AccountKeyNotFound(String),
51    #[error("account storage data with root {0} not found")]
52    AccountStorageRootNotFound(Word),
53    #[error("account storage data with index {0} not found")]
54    AccountStorageIndexNotFound(usize),
55    #[error("block header for block {0} not found")]
56    BlockHeaderNotFound(BlockNumber),
57    #[error("partial blockchain node at index {0} not found")]
58    PartialBlockchainNodeNotFound(u64),
59    #[error("error deserializing data from the store")]
60    DataDeserializationError(#[from] DeserializationError),
61    #[error("database-related non-query error: {0}")]
62    DatabaseError(String),
63    #[error("error parsing hex")]
64    HexParseError(#[from] HexParseError),
65    #[error("failed to convert int")]
66    InvalidInt(#[from] TryFromIntError),
67    #[error("note record error")]
68    NoteRecordError(#[from] NoteRecordError),
69    #[error("error in merkle store")]
70    MerkleStoreError(#[from] MerkleError),
71    #[error("error constructing mmr")]
72    MmrError(#[from] MmrError),
73    #[error("inclusion proof creation error")]
74    NoteInclusionProofError(#[from] NoteError),
75    #[error("note tag {0} is already being tracked")]
76    NoteTagAlreadyTracked(u64),
77    #[error("note transport cursor not found")]
78    NoteTransportCursorNotFound,
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("error with the SMT proof")]
86    SmtProofError(#[from] SmtProofError),
87    #[error("error with a storage map")]
88    StorageMapError(#[from] StorageMapError),
89    #[error("error instantiating 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: {0}")]
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}