spl_token_group_interface/
error.rs

1//! Interface 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 TokenGroupError {
13    /// Size is greater than proposed max size
14    #[error("Size is greater than proposed max size")]
15    SizeExceedsNewMaxSize = 3_406_457_176,
16    /// Size is greater than max size
17    #[error("Size is greater than max size")]
18    SizeExceedsMaxSize,
19    /// Group is immutable
20    #[error("Group is immutable")]
21    ImmutableGroup,
22    /// Incorrect mint authority has signed the instruction
23    #[error("Incorrect mint authority has signed the instruction")]
24    IncorrectMintAuthority,
25    /// Incorrect update authority has signed the instruction
26    #[error("Incorrect update authority has signed the instruction")]
27    IncorrectUpdateAuthority,
28    /// Member account should not be the same as the group account
29    #[error("Member account should not be the same as the group account")]
30    MemberAccountIsGroupAccount,
31}
32
33impl From<TokenGroupError> for ProgramError {
34    fn from(e: TokenGroupError) -> Self {
35        ProgramError::Custom(e as u32)
36    }
37}
38
39impl<T> DecodeError<T> for TokenGroupError {
40    fn type_of() -> &'static str {
41        "TokenGroupError"
42    }
43}
44
45impl PrintProgramError for TokenGroupError {
46    fn print<E>(&self)
47    where
48        E: 'static
49            + std::error::Error
50            + DecodeError<E>
51            + PrintProgramError
52            + num_traits::FromPrimitive,
53    {
54        match self {
55            TokenGroupError::SizeExceedsNewMaxSize => {
56                msg!("Size is greater than proposed max size")
57            }
58            TokenGroupError::SizeExceedsMaxSize => {
59                msg!("Size is greater than max size")
60            }
61            TokenGroupError::ImmutableGroup => {
62                msg!("Group is immutable")
63            }
64            TokenGroupError::IncorrectMintAuthority => {
65                msg!("Incorrect mint authority has signed the instruction",)
66            }
67            TokenGroupError::IncorrectUpdateAuthority => {
68                msg!("Incorrect update authority has signed the instruction",)
69            }
70            TokenGroupError::MemberAccountIsGroupAccount => {
71                msg!("Member account should not be the same as the group account",)
72            }
73        }
74    }
75}