gmsol_solana_utils/
error.rs1use solana_sdk::pubkey::Pubkey;
2
3#[derive(Debug, thiserror::Error)]
5pub enum Error {
6 #[error("account not found: {0}")]
8 AccountNotFound(Pubkey),
9 #[error("parse url: {0}")]
11 ParseUrl(#[from] url::ParseError),
12 #[error("parse cluster: {0}")]
14 ParseCluster(&'static str),
15 #[error("merge transaction: {0}")]
17 MergeTransaction(&'static str),
18 #[error("add transaction: {0}")]
20 AddTransaction(&'static str),
21 #[error("compile message: {0}")]
23 CompileMessage(#[from] solana_sdk::message::CompileError),
24 #[cfg(feature = "solana-client")]
26 #[error("client: {0}")]
27 Client(#[from] Box<solana_client::client_error::ClientError>),
28 #[error("signer: {0}")]
30 Signer(#[from] solana_sdk::signer::SignerError),
31 #[error("custom: {0}")]
33 Custom(String),
34 #[cfg(feature = "solana-rpc-client-api")]
36 #[error("rpc-client-api: {0}")]
37 RpcClientApi(Box<solana_rpc_client_api::client_error::Error>),
38 #[cfg(feature = "serde_json")]
40 #[error("json: {0}")]
41 Json(#[from] serde_json::Error),
42 #[cfg(feature = "anchor-lang")]
44 #[error("anchor: {0}")]
45 Anchor(#[from] anchor_lang::error::Error),
46 #[cfg(feature = "reqwest")]
48 #[error("reqwest: {0}")]
49 Reqwest(#[from] reqwest::Error),
50}
51
52impl<T> From<(T, Error)> for Error {
53 fn from(value: (T, crate::Error)) -> Self {
54 value.1
55 }
56}
57
58impl Error {
59 pub fn custom(msg: impl ToString) -> Self {
61 Self::Custom(msg.to_string())
62 }
63}
64
65#[cfg(feature = "solana-rpc-client-api")]
66impl From<solana_rpc_client_api::client_error::Error> for Error {
67 fn from(err: solana_rpc_client_api::client_error::Error) -> Self {
68 Self::RpcClientApi(Box::new(err))
69 }
70}