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