use solana_sdk::pubkey::Pubkey;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("account not found: {0}")]
AccountNotFound(Pubkey),
#[error("parse url: {0}")]
ParseUrl(#[from] url::ParseError),
#[error("parse cluster: {0}")]
ParseCluster(&'static str),
#[error("merge transaction: {0}")]
MergeTransaction(&'static str),
#[error("add transaction: {0}")]
AddTransaction(&'static str),
#[error("compile message: {0}")]
CompileMessage(#[from] solana_sdk::message::CompileError),
#[cfg(feature = "solana-client")]
#[error("client: {0}")]
Client(#[from] Box<solana_client::client_error::ClientError>),
#[error("signer: {0}")]
Signer(#[from] solana_sdk::signer::SignerError),
#[error("custom: {0}")]
Custom(String),
#[cfg(feature = "solana-rpc-client-api")]
#[error("rpc-client-api: {0}")]
RpcClientApi(Box<solana_rpc_client_api::client_error::Error>),
#[cfg(feature = "serde_json")]
#[error("json: {0}")]
Json(#[from] serde_json::Error),
#[cfg(feature = "anchor-lang")]
#[error("anchor: {0}")]
Anchor(#[from] anchor_lang::error::Error),
#[cfg(feature = "reqwest")]
#[error("reqwest: {0}")]
Reqwest(#[from] reqwest::Error),
}
impl<T> From<(T, Error)> for Error {
fn from(value: (T, crate::Error)) -> Self {
value.1
}
}
impl Error {
pub fn custom(msg: impl ToString) -> Self {
Self::Custom(msg.to_string())
}
}
#[cfg(feature = "solana-rpc-client-api")]
impl From<solana_rpc_client_api::client_error::Error> for Error {
fn from(err: solana_rpc_client_api::client_error::Error) -> Self {
Self::RpcClientApi(Box::new(err))
}
}