Skip to main content

rialo_s_spl_token_group_interface/
error.rs

1// Copyright (c) Subzero Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3// This file is either (a) original to Subzero Labs, Inc. or (b) derived from the Anza codebase and modified by Subzero Labs, Inc.
4
5//! Interface error types
6
7use num_traits::FromPrimitive;
8use rialo_s_decode_error::DecodeError;
9use rialo_s_msg::msg;
10use rialo_s_program_error::{PrintProgramError, ProgramError, ToStr};
11
12/// Errors that may be returned by the interface.
13#[repr(u32)]
14#[derive(
15    Clone,
16    Debug,
17    Eq,
18    thiserror::Error,
19    num_derive::FromPrimitive,
20    num_enum::TryFromPrimitive,
21    PartialEq,
22)]
23pub enum TokenGroupError {
24    /// Size is greater than proposed max size
25    #[error("Size is greater than proposed max size")]
26    SizeExceedsNewMaxSize = 3_406_457_176,
27    /// Size is greater than max size
28    #[error("Size is greater than max size")]
29    SizeExceedsMaxSize,
30    /// Group is immutable
31    #[error("Group is immutable")]
32    ImmutableGroup,
33    /// Incorrect mint authority has signed the instruction
34    #[error("Incorrect mint authority has signed the instruction")]
35    IncorrectMintAuthority,
36    /// Incorrect update authority has signed the instruction
37    #[error("Incorrect update authority has signed the instruction")]
38    IncorrectUpdateAuthority,
39    /// Member account should not be the same as the group account
40    #[error("Member account should not be the same as the group account")]
41    MemberAccountIsGroupAccount,
42}
43
44impl From<TokenGroupError> for ProgramError {
45    fn from(e: TokenGroupError) -> Self {
46        ProgramError::Custom(e as u32)
47    }
48}
49
50impl DecodeError<TokenGroupError> for TokenGroupError {
51    fn type_of() -> &'static str {
52        "TokenGroupError"
53    }
54    fn decode_custom_error_to_enum(e: u32) -> Option<TokenGroupError> {
55        TokenGroupError::from_u32(e)
56    }
57}
58
59impl PrintProgramError for TokenGroupError {
60    fn print<E>(&self)
61    where
62        E: 'static
63            + std::error::Error
64            + rialo_s_decode_error::DecodeError<E>
65            + PrintProgramError
66            + num_traits::FromPrimitive,
67    {
68        msg!("{}", self.to_str());
69    }
70}
71
72impl ToStr for TokenGroupError {
73    fn to_str(&self) -> &'static str {
74        match self {
75            TokenGroupError::SizeExceedsNewMaxSize => "Size is greater than proposed max size",
76            TokenGroupError::SizeExceedsMaxSize => "Size is greater than max size",
77            TokenGroupError::ImmutableGroup => "Group is immutable",
78            TokenGroupError::IncorrectMintAuthority => {
79                "Incorrect mint authority has signed the instruction"
80            }
81            TokenGroupError::IncorrectUpdateAuthority => {
82                "Incorrect update authority has signed the instruction"
83            }
84            TokenGroupError::MemberAccountIsGroupAccount => {
85                "Member account should not be the same as the group account"
86            }
87        }
88    }
89}