Skip to main content

miden_client/store/
errors.rs

1use alloc::string::String;
2
3use miden_protocol::account::AccountId;
4use miden_protocol::asset::AssetId;
5use miden_protocol::block::BlockNumber;
6use miden_protocol::crypto::merkle::MerkleError;
7use miden_protocol::crypto::merkle::mmr::MmrError;
8use miden_protocol::errors::{
9    AccountError,
10    AccountIdError,
11    AccountPatchError,
12    AssetError,
13    AssetVaultError,
14    NoteError,
15    StorageMapError,
16};
17use miden_protocol::utils::serde::DeserializationError;
18use miden_protocol::{Word, WordError};
19use miden_tx::DataStoreError;
20use thiserror::Error;
21
22// STORE ERROR
23// ================================================================================================
24
25/// Errors generated from the store.
26#[derive(Debug, Error)]
27#[allow(clippy::large_enum_variant)]
28pub enum StoreError {
29    #[error("protocol configuration {0} is not stored; sync the client to get it from the node")]
30    ProtocolConfigNotFound(Word),
31    #[error("stored protocol configuration does not match commitment {0}")]
32    ProtocolConfigCommitmentMismatch(Word),
33    #[error("asset error")]
34    AssetError(#[from] AssetError),
35    #[error("asset vault error")]
36    AssetVaultError(#[from] AssetVaultError),
37    #[error("account data wasn't found for account id {0}")]
38    AccountDataNotFound(AccountId),
39    #[error("account patch error")]
40    AccountPatchError(#[from] AccountPatchError),
41    #[error("account error")]
42    AccountError(#[from] AccountError),
43    #[error("invalid account ID")]
44    AccountIdError(#[from] AccountIdError),
45    #[error("stored account commitment does not match the expected commitment for account {0}")]
46    AccountCommitmentMismatch(AccountId),
47    #[error("account storage data with root {0} not found")]
48    AccountStorageRootNotFound(Word),
49    #[error("block header for block {0} not found")]
50    BlockHeaderNotFound(BlockNumber),
51    #[error("partial blockchain node at index {0} not found")]
52    PartialBlockchainNodeNotFound(u64),
53    #[error("failed to deserialize data from the store")]
54    DataDeserializationError(#[from] DeserializationError),
55    #[error("database-related non-query error: {0}")]
56    DatabaseError(String),
57    #[error("transient database error, the operation can be retried: {0}")]
58    DatabaseTransientError(String),
59    #[error("permanent database error: {0}")]
60    DatabasePermanentError(String),
61    #[error("merkle store error")]
62    MerkleStoreError(#[from] MerkleError),
63    #[error("failed to construct Merkle Mountain Range (MMR)")]
64    MmrError(#[from] MmrError),
65    #[error("failed to create note inclusion proof")]
66    NoteInclusionProofError(#[from] NoteError),
67    #[error("note script with root {0} not found")]
68    NoteScriptNotFound(String),
69    #[error("failed to parse data retrieved from the database: {0}")]
70    ParsingError(String),
71    #[error("failed to retrieve data from the database: {0}")]
72    QueryError(String),
73    #[error("account storage map error")]
74    StorageMapError(#[from] StorageMapError),
75    #[error("vault key {0:?} (hashed to {1}) is not tracked in the vault")]
76    VaultKeyNotTracked(AssetId, Word),
77    #[error("failed to parse word")]
78    WordError(#[from] WordError),
79}
80
81impl From<StoreError> for DataStoreError {
82    fn from(value: StoreError) -> Self {
83        match value {
84            StoreError::AccountDataNotFound(account_id) => {
85                DataStoreError::AccountNotFound(account_id)
86            },
87            err => DataStoreError::other_with_source("store error", err),
88        }
89    }
90}