1use {
3 clone_solana_decode_error::DecodeError,
4 clone_solana_msg::msg,
5 clone_solana_program_error::{PrintProgramError, ProgramError},
6};
7
8#[repr(u32)]
10#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error, num_derive::FromPrimitive)]
11pub enum PodSliceError {
12 #[error("Error in checked math operation")]
14 CalculationFailure,
15 #[error("Provided byte buffer too small for expected type")]
17 BufferTooSmall,
18 #[error("Provided byte buffer too large for expected type")]
20 BufferTooLarge,
21}
22
23impl From<PodSliceError> for ProgramError {
24 fn from(e: PodSliceError) -> Self {
25 ProgramError::Custom(e as u32)
26 }
27}
28
29impl<T> clone_solana_decode_error::DecodeError<T> for PodSliceError {
30 fn type_of() -> &'static str {
31 "PodSliceError"
32 }
33}
34
35impl PrintProgramError for PodSliceError {
36 fn print<E>(&self)
37 where
38 E: 'static
39 + std::error::Error
40 + DecodeError<E>
41 + PrintProgramError
42 + num_traits::FromPrimitive,
43 {
44 match self {
45 PodSliceError::CalculationFailure => {
46 msg!("Error in checked math operation")
47 }
48 PodSliceError::BufferTooSmall => {
49 msg!("Provided byte buffer too small for expected type")
50 }
51 PodSliceError::BufferTooLarge => {
52 msg!("Provided byte buffer too large for expected type")
53 }
54 }
55 }
56}