spl_transfer_hook_interface/
error.rs

1//! Error types
2
3use {
4    solana_decode_error::DecodeError,
5    solana_msg::msg,
6    solana_program_error::{PrintProgramError, ProgramError},
7};
8
9/// Errors that may be returned by the interface.
10#[repr(u32)]
11#[derive(Clone, Debug, Eq, thiserror::Error, num_derive::FromPrimitive, PartialEq)]
12pub enum TransferHookError {
13    /// Incorrect account provided
14    #[error("Incorrect account provided")]
15    IncorrectAccount = 2_110_272_652,
16    /// Mint has no mint authority
17    #[error("Mint has no mint authority")]
18    MintHasNoMintAuthority,
19    /// Incorrect mint authority has signed the instruction
20    #[error("Incorrect mint authority has signed the instruction")]
21    IncorrectMintAuthority,
22    /// Program called outside of a token transfer
23    #[error("Program called outside of a token transfer")]
24    ProgramCalledOutsideOfTransfer,
25}
26
27impl From<TransferHookError> for ProgramError {
28    fn from(e: TransferHookError) -> Self {
29        ProgramError::Custom(e as u32)
30    }
31}
32
33impl<T> DecodeError<T> for TransferHookError {
34    fn type_of() -> &'static str {
35        "TransferHookError"
36    }
37}
38
39impl PrintProgramError for TransferHookError {
40    fn print<E>(&self)
41    where
42        E: 'static
43            + std::error::Error
44            + DecodeError<E>
45            + PrintProgramError
46            + num_traits::FromPrimitive,
47    {
48        match self {
49            TransferHookError::IncorrectAccount => {
50                msg!("Incorrect account provided")
51            }
52            TransferHookError::MintHasNoMintAuthority => {
53                msg!("Mint has no mint authority")
54            }
55            TransferHookError::IncorrectMintAuthority => {
56                msg!("Incorrect mint authority has signed the instruction")
57            }
58            TransferHookError::ProgramCalledOutsideOfTransfer => {
59                msg!("Program called outside of a token transfer")
60            }
61        }
62    }
63}