soroban_client/
error.rs

1/// Error Handling in `soroban_client` crate
2/// This module defines all possible error types used in the `soroban_client` crate.
3use stellar_baselib::xdr::SorobanTransactionData;
4use thiserror::Error;
5
6/// Possible error for AuthMode in simulation request
7#[derive(Error, Debug)]
8pub enum AuthModeError {
9    /// Error while converting AuthMode
10    #[error("Invalid auth mode: {0}, should be one of 'enforce', 'record', 'record_allow_nonroot' or be omitted")]
11    Invalid(String),
12}
13
14/// Possible error types
15#[derive(Error, Debug)]
16pub enum Error {
17    /// Error for invalid RPC URL
18    #[error(transparent)]
19    InvalidRpc(#[from] InvalidRpcUrl),
20    /// Error when XDR processing fails
21    #[error("XdrError")]
22    XdrError,
23    /// Error when JSON parsing fails, with a descriptive message
24    #[error("JsonError: could not parse {0}")]
25    JsonError(String),
26    /// Error for network-related failures
27    #[error("NetworkError")]
28    NetworkError(#[from] reqwest::Error),
29    /// Error when an account is not found
30    #[error("AccountError")]
31    AccountNotFound,
32    /// Error when contract data is missing
33    #[error("ContractError")]
34    ContractDataNotFound,
35    /// Error for general transaction failures
36    #[error("TransactionError")]
37    TransactionError,
38    /// Error for invalid Soroban transactions
39    #[error("InvalidSorobanTransaction")]
40    InvalidSorobanTransaction,
41    /// Error when a simulation fails
42    #[error("SimulationFailed: `{0}`")]
43    SimulationFailed(String),
44    /// Error when restoration is required with additional data
45    #[error("RestorationRequired")]
46    RestorationRequired(i64, SorobanTransactionData),
47    /// Error for RPC failures, includes code and message
48    #[error("RPCError {code}: {message}")]
49    RPCError {
50        /// The error code returned from the RPC
51        code: i32,
52        /// The error message returned from the RPC
53        message: String,
54    },
55    /// Unexpected error, should be reported
56    #[error("UnexpectedError")]
57    UnexpectedError,
58    /// Error when Friendbot is not available on the current network
59    #[error("NoFriendbot")]
60    NoFriendbot,
61}
62
63/// Possible  errors for invalid RPC URLs
64#[derive(Error, Debug)]
65pub enum InvalidRpcUrl {
66    /// Error when the URL scheme is not HTTP or HTTPS
67    #[error("The RPC Url scheme should be http or https")]
68    NotHttpScheme,
69    /// Error when insecure HTTP URLs are used without explicit permission
70    #[error("Http scheme requires the option allow_http: true")]
71    UnsecureHttpNotAllowed,
72    /// Error when the provided URL is invalid
73    #[error("InvalidUrl")]
74    InvalidUri,
75}