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, TransactionScriptError, account::AccountId,
9    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(#[source] AssetError),
47    #[error("account data wasn't found for account id {0}")]
48    AccountDataNotFound(AccountId),
49    #[error("data deserialization error")]
50    DataDeserializationError(#[from] DeserializationError),
51    #[error("note with id {0} not found on chain")]
52    NoteNotFoundOnChain(NoteId),
53    #[error("error parsing hex")]
54    HexParseError(#[from] HexParseError),
55    #[error("can't add new account without seed")]
56    AddNewAccountWithoutSeed,
57    #[error("error with merkle path")]
58    MerkleError(#[from] MerkleError),
59    #[error("the transaction didn't produce the expected notes corresponding to note ids")]
60    MissingOutputNotes(Vec<NoteId>),
61    #[error("note error")]
62    NoteError(#[from] NoteError),
63    #[error("note import error: {0}")]
64    NoteImportError(String),
65    #[error("note record error")]
66    NoteRecordError(#[from] NoteRecordError),
67    #[error("no consumable note for account {0}")]
68    NoConsumableNoteForAccount(AccountId),
69    #[error("rpc api error")]
70    RpcError(#[from] RpcError),
71    #[error("recency condition error")]
72    RecencyConditionError(String),
73    #[error("note screener error")]
74    NoteScreenerError(#[from] NoteScreenerError),
75    #[error("store error")]
76    StoreError(#[from] StoreError),
77    #[error("transaction executor error")]
78    TransactionExecutorError(#[from] TransactionExecutorError),
79    #[error("transaction prover error")]
80    TransactionProvingError(#[from] TransactionProverError),
81    #[error("transaction request error")]
82    TransactionRequestError(#[from] TransactionRequestError),
83    #[error("transaction script builder error")]
84    AccountInterfaceError(#[from] AccountInterfaceError),
85    #[error("transaction script error")]
86    TransactionScriptError(#[source] TransactionScriptError),
87    #[error("client initialization error: {0}")]
88    ClientInitializationError(String),
89}
90
91// CONVERSIONS
92// ================================================================================================
93
94impl From<ClientError> for String {
95    fn from(err: ClientError) -> String {
96        err.to_string()
97    }
98}
99
100// ID PREFIX FETCH ERROR
101// ================================================================================================
102
103/// Error when Looking for a specific ID from a partial ID.
104#[derive(Debug, Error)]
105pub enum IdPrefixFetchError {
106    /// No matches were found for the ID prefix.
107    #[error("no matches were found with the {0}")]
108    NoMatch(String),
109    /// Multiple entities matched with the ID prefix.
110    #[error("found more than one element for the provided {0} and only one match is expected")]
111    MultipleMatches(String),
112}