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("partial MMR has a forest that does not fit within a u32")]
60    InvalidPartialMmrForest,
61    #[error("can't add new account without seed")]
62    AddNewAccountWithoutSeed,
63    #[error("error with merkle path")]
64    MerkleError(#[from] MerkleError),
65    #[error(
66        "the transaction didn't produce the output notes with the expected recipient digests ({0:?})"
67    )]
68    MissingOutputRecipients(Vec<Word>),
69    #[error("note error")]
70    NoteError(#[from] NoteError),
71    #[error("note checker error")]
72    NoteCheckerError(#[from] NoteCheckerError),
73    #[error("note import error: {0}")]
74    NoteImportError(String),
75    #[error("error while converting input note")]
76    NoteRecordConversionError(#[from] NoteRecordError),
77    #[error("no consumable note for account {0}")]
78    NoConsumableNoteForAccount(AccountId),
79    #[error("rpc api error")]
80    RpcError(#[from] RpcError),
81    #[error("recency condition error: {0}")]
82    RecencyConditionError(String),
83    #[error("note screener error")]
84    NoteScreenerError(#[from] NoteScreenerError),
85    #[error("store error")]
86    StoreError(#[from] StoreError),
87    #[error("transaction executor error")]
88    TransactionExecutorError(#[from] TransactionExecutorError),
89    #[error("transaction input error")]
90    TransactionInputError(#[source] TransactionInputError),
91    #[error("transaction prover error")]
92    TransactionProvingError(#[from] TransactionProverError),
93    #[error("transaction request error")]
94    TransactionRequestError(#[from] TransactionRequestError),
95    #[error("transaction script builder error")]
96    AccountInterfaceError(#[from] AccountInterfaceError),
97    #[error("transaction script error")]
98    TransactionScriptError(#[source] TransactionScriptError),
99    #[error("client initialization error: {0}")]
100    ClientInitializationError(String),
101}
102
103// CONVERSIONS
104// ================================================================================================
105
106impl From<ClientError> for String {
107    fn from(err: ClientError) -> String {
108        err.to_string()
109    }
110}
111
112// ID PREFIX FETCH ERROR
113// ================================================================================================
114
115/// Error when Looking for a specific ID from a partial ID.
116#[derive(Debug, Error)]
117pub enum IdPrefixFetchError {
118    /// No matches were found for the ID prefix.
119    #[error("no matches were found with the {0}")]
120    NoMatch(String),
121    /// Multiple entities matched with the ID prefix.
122    #[error("found more than one element for the provided {0} and only one match is expected")]
123    MultipleMatches(String),
124}