solana_transaction_utils/
error.rs

1use solana_sdk::{message::CompileError, transaction::TransactionError};
2
3#[derive(Debug, thiserror::Error, Clone)]
4pub enum Error {
5    #[error("RPC error: {0}")]
6    RpcError(String),
7    #[error("Instruction error: {0}")]
8    InstructionError(#[from] solana_sdk::instruction::InstructionError),
9    #[error("Serialization error: {0}")]
10    SerializationError(String),
11    #[error("Compile error: {0}")]
12    CompileError(#[from] CompileError),
13    #[error("Signer error: {0}")]
14    SignerError(String),
15    #[error("Ix group too large")]
16    IxGroupTooLarge,
17    #[error("Max retries exceeded")]
18    MaxRetriesExceeded,
19    #[error("Transaction error: {0}")]
20    TransactionError(TransactionError),
21    #[error("Simulated transaction error: {0}")]
22    SimulatedTransactionError(TransactionError),
23    #[error("Raw simulated transaction error: {0}")]
24    RawSimulatedTransactionError(String),
25    #[error("Raw transaction error: {0}")]
26    RawTransactionError(String),
27    #[error("Fee too high")]
28    FeeTooHigh,
29    #[error("Transaction has failed too many retries and gone stale")]
30    StaleTransaction,
31    #[error("message channel closed")]
32    ChannelClosed,
33}
34
35impl From<solana_client::client_error::ClientError> for Error {
36    fn from(value: solana_client::client_error::ClientError) -> Self {
37        Self::RpcError(value.to_string())
38    }
39}
40
41impl<T> From<tokio::sync::mpsc::error::SendError<T>> for Error {
42    fn from(_value: tokio::sync::mpsc::error::SendError<T>) -> Self {
43        Self::ChannelClosed
44    }
45}
46
47impl Error {
48    pub fn signer<S: ToString>(str: S) -> Self {
49        Self::SignerError(str.to_string())
50    }
51
52    pub fn serialization<S: ToString>(str: S) -> Self {
53        Self::SerializationError(str.to_string())
54    }
55
56    pub fn channel_closed() -> Error {
57        Error::ChannelClosed
58    }
59}