light_client/rpc/
errors.rs

1use std::io;
2
3use light_sdk::error::LightSdkError;
4use solana_rpc_client_api::client_error::Error as ClientError;
5use solana_transaction_error::TransactionError;
6use thiserror::Error;
7
8use crate::indexer::IndexerError;
9
10#[derive(Error, Debug)]
11pub enum RpcError {
12    #[cfg(feature = "program-test")]
13    #[error("BanksError: {0}")]
14    BanksError(#[from] solana_banks_client::BanksClientError),
15
16    #[error("State tree lookup table not found")]
17    StateTreeLookupTableNotFound,
18
19    #[error("State tree lookup table must have a multiple of 3 addresses")]
20    InvalidStateTreeLookupTable,
21
22    #[error("Nullify table not found")]
23    NullifyTableNotFound,
24
25    #[error("TransactionError: {0}")]
26    TransactionError(#[from] TransactionError),
27
28    #[error("ClientError: {0}")]
29    ClientError(#[from] ClientError),
30
31    #[error("IoError: {0}")]
32    IoError(#[from] io::Error),
33
34    #[error("Error: `{0}`")]
35    CustomError(String),
36
37    #[error("Signing error: {0}")]
38    SigningError(String),
39
40    #[error("Assert Rpc Error: {0}")]
41    AssertRpcError(String),
42
43    /// The chosen warp slot is not in the future, so warp is not performed
44    #[error("Warp slot not in the future")]
45    InvalidWarpSlot,
46
47    #[cfg(feature = "program-test")]
48    #[error("LiteSVM Error: {0}")]
49    LiteSvmError(String),
50
51    #[error("Account {0} does not exist")]
52    AccountDoesNotExist(String),
53
54    #[error("Invalid response data.")]
55    InvalidResponseData,
56
57    #[error("Indexer not initialized.")]
58    IndexerNotInitialized,
59
60    #[error("Indexer error: {0}")]
61    IndexerError(#[from] IndexerError),
62
63    #[error(
64        "No state trees available, use rpc.get_latest_active_state_trees() to fetch state trees"
65    )]
66    NoStateTreesAvailable,
67
68    #[error("LightSdkError error: {0}")]
69    LightSdkError(#[from] LightSdkError),
70}
71
72impl From<light_event::error::ParseIndexerEventError> for RpcError {
73    fn from(e: light_event::error::ParseIndexerEventError) -> Self {
74        RpcError::CustomError(format!("ParseIndexerEventError: {}", e))
75    }
76}
77
78impl Clone for RpcError {
79    fn clone(&self) -> Self {
80        match self {
81            #[cfg(feature = "program-test")]
82            RpcError::BanksError(_) => RpcError::CustomError("BanksError".to_string()),
83            RpcError::TransactionError(e) => RpcError::TransactionError(e.clone()),
84            RpcError::ClientError(_) => RpcError::CustomError("ClientError".to_string()),
85            RpcError::IoError(e) => RpcError::IoError(e.kind().into()),
86            RpcError::CustomError(e) => RpcError::CustomError(e.clone()),
87            RpcError::SigningError(e) => RpcError::SigningError(e.clone()),
88            RpcError::AssertRpcError(e) => RpcError::AssertRpcError(e.clone()),
89            RpcError::InvalidWarpSlot => RpcError::InvalidWarpSlot,
90            RpcError::AccountDoesNotExist(e) => RpcError::AccountDoesNotExist(e.clone()),
91            RpcError::InvalidResponseData => RpcError::InvalidResponseData,
92            RpcError::IndexerNotInitialized => RpcError::IndexerNotInitialized,
93            RpcError::IndexerError(e) => RpcError::IndexerError(e.clone()),
94            RpcError::LightSdkError(e) => RpcError::CustomError(e.to_string()),
95            RpcError::StateTreeLookupTableNotFound => RpcError::StateTreeLookupTableNotFound,
96            RpcError::InvalidStateTreeLookupTable => RpcError::InvalidStateTreeLookupTable,
97            RpcError::NullifyTableNotFound => RpcError::NullifyTableNotFound,
98            RpcError::NoStateTreesAvailable => RpcError::NoStateTreesAvailable,
99            #[cfg(feature = "program-test")]
100            RpcError::LiteSvmError(e) => RpcError::LiteSvmError(e.clone()),
101        }
102    }
103}
104
105#[cfg(feature = "program-test")]
106impl From<litesvm::error::LiteSVMError> for RpcError {
107    fn from(e: litesvm::error::LiteSVMError) -> Self {
108        RpcError::LiteSvmError(e.to_string())
109    }
110}