miden_client/store/
errors.rs

1use alloc::string::String;
2use core::num::TryFromIntError;
3
4use miden_objects::account::AccountId;
5use miden_objects::crypto::merkle::{MerkleError, MmrError, SmtProofError};
6use miden_objects::utils::{DeserializationError, HexParseError};
7use miden_objects::{
8    AccountError,
9    AccountIdError,
10    AddressError,
11    AssetError,
12    AssetVaultError,
13    NoteError,
14    StorageMapError,
15    TransactionScriptError,
16    Word,
17    WordError,
18};
19use miden_tx::DataStoreError;
20use thiserror::Error;
21
22use super::note_record::NoteRecordError;
23
24// STORE ERROR
25// ================================================================================================
26
27/// Errors generated from the store.
28#[derive(Debug, Error)]
29#[allow(clippy::large_enum_variant)]
30pub enum StoreError {
31    #[error("asset error")]
32    AssetError(#[from] AssetError),
33    #[error("asset vault error")]
34    AssetVaultError(#[from] AssetVaultError),
35    #[error("account code data with root {0} not found")]
36    AccountCodeDataNotFound(Word),
37    #[error("account data wasn't found for account id {0}")]
38    AccountDataNotFound(AccountId),
39    #[error("account error")]
40    AccountError(#[from] AccountError),
41    #[error("address error")]
42    AddressError(#[from] AddressError),
43    #[error("account id error")]
44    AccountIdError(#[from] AccountIdError),
45    #[error("account commitment {0} already exists")]
46    AccountCommitmentAlreadyExists(Word),
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    AccountStorageNotFound(Word),
53    #[error("partial blockchain node at index {0} not found")]
54    PartialBlockchainNodeNotFound(u64),
55    #[error("error deserializing data from the store")]
56    DataDeserializationError(#[from] DeserializationError),
57    #[error("database-related non-query error: {0}")]
58    DatabaseError(String),
59    #[error("error parsing hex")]
60    HexParseError(#[from] HexParseError),
61    #[error("failed to convert int")]
62    InvalidInt(#[from] TryFromIntError),
63    #[error("note record error")]
64    NoteRecordError(#[from] NoteRecordError),
65    #[error("error in merkle store")]
66    MerkleStoreError(#[from] MerkleError),
67    #[error("error constructing mmr")]
68    MmrError(#[from] MmrError),
69    #[error("inclusion proof creation error")]
70    NoteInclusionProofError(#[from] NoteError),
71    #[error("note tag {0} is already being tracked")]
72    NoteTagAlreadyTracked(u64),
73    #[error("note transport cursor not found")]
74    NoteTransportCursorNotFound,
75    #[error("note script with root {0} not found")]
76    NoteScriptNotFound(String),
77    #[error("failed to parse data retrieved from the database: {0}")]
78    ParsingError(String),
79    #[error("failed to retrieve data from the database: {0}")]
80    QueryError(String),
81    #[error("error with the SMT proof")]
82    SmtProofError(#[from] SmtProofError),
83    #[error("error with a storage map")]
84    StorageMapError(#[from] StorageMapError),
85    #[error("error instantiating transaction script")]
86    TransactionScriptError(#[from] TransactionScriptError),
87    #[error("account vault data for root {0} not found")]
88    VaultDataNotFound(Word),
89    #[error("failed to parse word: {0}")]
90    WordError(#[from] WordError),
91}
92
93impl From<StoreError> for DataStoreError {
94    fn from(value: StoreError) -> Self {
95        match value {
96            StoreError::AccountDataNotFound(account_id) => {
97                DataStoreError::AccountNotFound(account_id)
98            },
99            err => DataStoreError::other_with_source("store error", err),
100        }
101    }
102}