spl_transfer_hook_interface/
error.rs

1//! Error types
2
3use solana_program_error::{ProgramError, ToStr};
4
5/// Errors that may be returned by the interface.
6#[repr(u32)]
7#[derive(Clone, Debug, Eq, thiserror::Error, num_derive::FromPrimitive, PartialEq)]
8pub enum TransferHookError {
9    /// Incorrect account provided
10    #[error("Incorrect account provided")]
11    IncorrectAccount = 2_110_272_652,
12    /// Mint has no mint authority
13    #[error("Mint has no mint authority")]
14    MintHasNoMintAuthority,
15    /// Incorrect mint authority has signed the instruction
16    #[error("Incorrect mint authority has signed the instruction")]
17    IncorrectMintAuthority,
18    /// Program called outside of a token transfer
19    #[error("Program called outside of a token transfer")]
20    ProgramCalledOutsideOfTransfer,
21}
22
23impl From<TransferHookError> for ProgramError {
24    fn from(e: TransferHookError) -> Self {
25        ProgramError::Custom(e as u32)
26    }
27}
28
29impl ToStr for TransferHookError {
30    fn to_str(&self) -> &'static str {
31        match self {
32            TransferHookError::IncorrectAccount => "Incorrect account provided",
33            TransferHookError::MintHasNoMintAuthority => "Mint has no mint authority",
34            TransferHookError::IncorrectMintAuthority => {
35                "Incorrect mint authority has signed the instruction"
36            }
37            TransferHookError::ProgramCalledOutsideOfTransfer => {
38                "Program called outside of a token transfer"
39            }
40        }
41    }
42}