miden_client/
errors.rs

1use alloc::string::{String, ToString};
2use alloc::vec::Vec;
3
4use miden_lib::account::interface::AccountInterfaceError;
5use miden_objects::account::AccountId;
6use miden_objects::crypto::merkle::MerkleError;
7use miden_objects::note::NoteId;
8use miden_objects::{
9    AccountError,
10    AssetError,
11    NoteError,
12    PartialBlockchainError,
13    TransactionInputError,
14    TransactionScriptError,
15    Word,
16};
17// RE-EXPORTS
18// ================================================================================================
19pub use miden_tx::AuthenticationError;
20use miden_tx::utils::{DeserializationError, HexParseError};
21use miden_tx::{NoteCheckerError, TransactionExecutorError, TransactionProverError};
22use thiserror::Error;
23
24use crate::note::NoteScreenerError;
25use crate::rpc::RpcError;
26use crate::store::{NoteRecordError, StoreError};
27use crate::transaction::TransactionRequestError;
28
29// CLIENT ERROR
30// ================================================================================================
31
32/// Errors generated by the client.
33#[derive(Debug, Error)]
34pub enum ClientError {
35    #[error("account with id {0} is already being tracked")]
36    AccountAlreadyTracked(AccountId),
37    #[error("account error")]
38    AccountError(#[from] AccountError),
39    #[error("account with id {0} is locked")]
40    AccountLocked(AccountId),
41    #[error("network account commitment {0} doesn't match the imported account commitment")]
42    AccountCommitmentMismatch(Word),
43    #[error("account with id {0} is private")]
44    AccountIsPrivate(AccountId),
45    #[error("account nonce is too low to import")]
46    AccountNonceTooLow,
47    #[error("asset error")]
48    AssetError(#[from] AssetError),
49    #[error("account data wasn't found for account id {0}")]
50    AccountDataNotFound(AccountId),
51    #[error("error creating the partial blockchain")]
52    PartialBlockchainError(#[from] PartialBlockchainError),
53    #[error("data deserialization error")]
54    DataDeserializationError(#[from] DeserializationError),
55    #[error("note with id {0} not found on chain")]
56    NoteNotFoundOnChain(NoteId),
57    #[error("error parsing hex")]
58    HexParseError(#[from] HexParseError),
59    #[error("can't add new account without seed")]
60    AddNewAccountWithoutSeed,
61    #[error("error with merkle path")]
62    MerkleError(#[from] MerkleError),
63    #[error(
64        "the transaction didn't produce the output notes with the expected recipient digests ({0:?})"
65    )]
66    MissingOutputRecipients(Vec<Word>),
67    #[error("note error")]
68    NoteError(#[from] NoteError),
69    #[error("note checker error")]
70    NoteCheckerError(#[from] NoteCheckerError),
71    #[error("note import error: {0}")]
72    NoteImportError(String),
73    #[error("error while converting input note")]
74    NoteRecordConversionError(#[from] NoteRecordError),
75    #[error("no consumable note for account {0}")]
76    NoConsumableNoteForAccount(AccountId),
77    #[error("rpc api error")]
78    RpcError(#[from] RpcError),
79    #[error("recency condition error: {0}")]
80    RecencyConditionError(String),
81    #[error("note screener error")]
82    NoteScreenerError(#[from] NoteScreenerError),
83    #[error("store error")]
84    StoreError(#[from] StoreError),
85    #[error("transaction executor error")]
86    TransactionExecutorError(#[from] TransactionExecutorError),
87    #[error("transaction input error")]
88    TransactionInputError(#[source] TransactionInputError),
89    #[error("transaction prover error")]
90    TransactionProvingError(#[from] TransactionProverError),
91    #[error("transaction request error")]
92    TransactionRequestError(#[from] TransactionRequestError),
93    #[error("transaction script builder error")]
94    AccountInterfaceError(#[from] AccountInterfaceError),
95    #[error("transaction script error")]
96    TransactionScriptError(#[source] TransactionScriptError),
97    #[error("client initialization error: {0}")]
98    ClientInitializationError(String),
99}
100
101// CONVERSIONS
102// ================================================================================================
103
104impl From<ClientError> for String {
105    fn from(err: ClientError) -> String {
106        err.to_string()
107    }
108}
109
110// ID PREFIX FETCH ERROR
111// ================================================================================================
112
113/// Error when Looking for a specific ID from a partial ID.
114#[derive(Debug, Error)]
115pub enum IdPrefixFetchError {
116    /// No matches were found for the ID prefix.
117    #[error("no matches were found with the {0}")]
118    NoMatch(String),
119    /// Multiple entities matched with the ID prefix.
120    #[error("found more than one element for the provided {0} and only one match is expected")]
121    MultipleMatches(String),
122}