#[derive(Debug)]
#[allow(clippy::large_enum_variant)]
pub enum ClientError {
BondingCurveNotFound,
BondingCurveError(&'static str),
BorshError(std::io::Error),
SolanaClientError(solana_client::client_error::ClientError),
#[cfg(feature = "stream")]
PubsubClientError(solana_client::pubsub_client::PubsubClientError),
UploadMetadataError(Box<dyn std::error::Error>),
OtherError(String),
}
impl std::fmt::Display for ClientError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::BondingCurveNotFound => write!(f, "Bonding curve not found"),
Self::BondingCurveError(msg) => write!(f, "Bonding curve error: {}", msg),
Self::BorshError(err) => write!(f, "Borsh serialization error: {}", err),
Self::SolanaClientError(err) => write!(f, "Solana client error: {}", err),
#[cfg(feature = "stream")]
Self::PubsubClientError(err) => write!(f, "Solana pubsub client error: {}", err),
Self::UploadMetadataError(err) => write!(f, "Metadata upload error: {}", err),
Self::OtherError(msg) => write!(f, "Other error: {}", msg),
}
}
}
impl std::error::Error for ClientError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::BorshError(err) => Some(err),
Self::SolanaClientError(err) => Some(err),
#[cfg(feature = "stream")]
Self::PubsubClientError(err) => Some(err),
Self::UploadMetadataError(err) => Some(err.as_ref()),
_ => None,
}
}
}
impl From<solana_client::client_error::ClientError> for ClientError {
fn from(err: solana_client::client_error::ClientError) -> Self {
Self::SolanaClientError(err)
}
}
#[cfg(feature = "stream")]
impl From<solana_client::pubsub_client::PubsubClientError> for ClientError {
fn from(err: solana_client::pubsub_client::PubsubClientError) -> Self {
Self::PubsubClientError(err)
}
}