miden_client/
errors.rs

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