Skip to main content

mina_sdk/
error.rs

1use std::fmt;
2
3/// Errors returned by the Mina SDK.
4#[derive(Debug, thiserror::Error)]
5pub enum Error {
6    /// The GraphQL endpoint returned one or more errors.
7    #[error("GraphQL error in {query_name}: {messages}")]
8    Graphql {
9        query_name: String,
10        messages: String,
11        errors: Vec<GraphqlErrorEntry>,
12    },
13
14    /// Failed to connect after all retry attempts.
15    #[error("failed to execute {query_name} after {attempts} attempts: {source}")]
16    Connection {
17        query_name: String,
18        attempts: u32,
19        #[source]
20        source: reqwest::Error,
21    },
22
23    /// A required field was missing in the response.
24    #[error("missing field '{field}' in {query_name} response")]
25    MissingField { query_name: String, field: String },
26
27    /// Currency value would underflow (go negative).
28    #[error("currency underflow: {0} - {1} would be negative")]
29    CurrencyUnderflow(u64, u64),
30
31    /// Invalid currency format string.
32    #[error("invalid currency format: {0}")]
33    InvalidCurrency(String),
34
35    /// Account not found.
36    #[error("account not found: {0}")]
37    AccountNotFound(String),
38}
39
40/// A single error entry from a GraphQL response.
41#[derive(Debug, Clone)]
42pub struct GraphqlErrorEntry {
43    pub message: String,
44}
45
46impl fmt::Display for GraphqlErrorEntry {
47    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
48        write!(f, "{}", self.message)
49    }
50}
51
52pub type Result<T> = std::result::Result<T, Error>;