rush_ecs_svm/
error.rs

1use num_derive::FromPrimitive;
2use solana_program::{
3    decode_error::DecodeError,
4    msg,
5    program_error::{PrintProgramError, ProgramError},
6};
7use thiserror::Error;
8
9#[derive(Debug, Error, FromPrimitive)]
10pub enum RushStoreError {
11    #[error("invalid account data length")]
12    InvalidAccountDataLength, // 0
13}
14
15// allow .into() for Custom Error to ProgramError conversion
16impl From<RushStoreError> for ProgramError {
17    fn from(e: RushStoreError) -> Self {
18        // https://docs.rs/solana-program/latest/solana_program/program_error/enum.ProgramError.html#variant.Custom
19        ProgramError::Custom(e as u32)
20    }
21}
22
23impl<T> DecodeError<T> for RushStoreError {
24    fn type_of() -> &'static str {
25        "RushStoreError"
26    }
27}
28
29impl PrintProgramError for RushStoreError {
30    fn print<E>(&self) {
31        msg!(&self.to_string());
32    }
33}