rathe_storage_program/
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/// Custom error implements the num_traits::FromPrimitive trait
10/// to participate in the PrintProgramError implementation.
11#[derive(Clone, Error, Debug, FromPrimitive, Eq, PartialEq)]
12pub enum StorageError {
13    #[error("Invalid operation has been invoked")]
14    InvalidOperation,
15}
16
17/// Allow a StorageError to be converted into a ProgramError one.
18impl From<StorageError> for ProgramError {
19    fn from(e: StorageError) -> Self {
20        ProgramError::Custom(e as u32)
21    }
22}
23
24/// Allow to print a StorageError in a Solana program.
25impl<T> DecodeError<T> for StorageError {
26    fn type_of() -> &'static str {
27        "Storage Error"
28    }
29}
30
31impl PrintProgramError for StorageError {
32    fn print<E>(&self) {
33        msg!(&self.to_string())
34    }
35}