use num_derive::FromPrimitive;
use solana_program::{
decode_error::DecodeError,
msg,
program_error::{PrintProgramError, ProgramError},
};
use thiserror::Error;
#[derive(Error, Clone, Debug, Eq, PartialEq, FromPrimitive)]
pub enum CounterError {
#[error("Error deserializing an account")]
DeserializationError,
#[error("Error serializing an account")]
SerializationError,
#[error("Invalid program owner. This likely mean the provided account does not exist")]
InvalidProgramOwner,
#[error("Invalid PDA derivation")]
InvalidPda,
#[error("Expected empty account")]
ExpectedEmptyAccount,
#[error("Expected non empty account")]
ExpectedNonEmptyAccount,
#[error("Expected signer account")]
ExpectedSignerAccount,
#[error("Expected writable account")]
ExpectedWritableAccount,
#[error("Account mismatch")]
AccountMismatch,
#[error("Invalid account key")]
InvalidAccountKey,
#[error("Numerical overflow")]
NumericalOverflow,
}
impl PrintProgramError for CounterError {
fn print<E>(&self) {
msg!(&self.to_string());
}
}
impl From<CounterError> for ProgramError {
fn from(e: CounterError) -> Self {
ProgramError::Custom(e as u32)
}
}
impl<T> DecodeError<T> for CounterError {
fn type_of() -> &'static str {
"Mpl Project Name Error"
}
}