mpl_trifle/
error.rs

1use mpl_token_metadata::solana_program::msg;
2use num_derive::FromPrimitive;
3use solana_program::{
4    decode_error::DecodeError,
5    program_error::{PrintProgramError, ProgramError},
6};
7use thiserror::Error;
8
9#[derive(Error, Debug, FromPrimitive, Copy, Clone, Eq, PartialEq)]
10pub enum TrifleError {
11    /// 0 - Numerical Overflow
12    #[error("Numerical Overflow")]
13    NumericalOverflow,
14
15    /// 1 - Invalid account
16    #[error("Invalid account")]
17    InvalidAccount,
18
19    /// 2 - Invalid Escrow Constraint Model
20    #[error("Invalid Escrow Constraint Model")]
21    InvalidEscrowConstraintModel,
22
23    /// 3 - Invalid Escrow Constraint
24    #[error("Invalid Escrow Constraint")]
25    InvalidEscrowConstraint,
26
27    /// 4 - Escrow Constraint Violation
28    #[error("Escrow Constraint Violation")]
29    EscrowConstraintViolation,
30
31    /// 5 - Invalid Update Authority
32    #[error("Invalid Update Authority")]
33    InvalidUpdateAuthority,
34
35    /// 6 - Failed to create pubkey
36    #[error("Failed to create pubkey")]
37    FailedToCreatePubkey,
38
39    /// 7 - Data type mismatch
40    #[error("Data type mismatch")]
41    DataTypeMismatch,
42
43    /// 8 - Constraint already exists
44    #[error("Constraint already exists")]
45    ConstraintAlreadyExists,
46
47    /// 9 - Token limit exceeded
48    #[error("Token Limit Exceeded")]
49    TokenLimitExceeded,
50
51    /// 10 - Failed to find the token amount
52    #[error("Failed to find Token Amount")]
53    FailedToFindTokenAmount,
54
55    /// 11 - The collection metadata is invalid
56    #[error("Invalid Collection Metadata")]
57    InvalidCollectionMetadata,
58
59    /// 12 - This set of Transfer Effects can not be used together
60    #[error("Provided Transfer Effects are not compatible")]
61    TransferEffectConflict,
62
63    /// 13 - The freeze authority is not set
64    #[error("Freeze Authority Not Set")]
65    FreezeAuthorityNotSet,
66
67    /// 14 - Cannot burn Print Edition
68    #[error("Cannot burn Print Edition")]
69    CannotBurnPrintEdition,
70
71    /// 15 - The constraint key was not found
72    #[error("Constraint Key Not Found")]
73    ConstraintKeyNotFound,
74
75    /// 16 - The data failed to serialize
76    #[error("Failed to serialize")]
77    FailedToSerialize,
78
79    /// 17 - Account data borrow failed
80    #[error("Failed to borrow account data")]
81    FailedToBorrowAccountData,
82
83    /// 18 - Failed to deserialize the collection
84    #[error("Failed to deserialize collection")]
85    InvalidCollection,
86
87    /// 19 - Only the holder is allowed to perform this action
88    #[error("Only the holder is allowed to perform this action")]
89    MustBeHolder,
90
91    /// 20 - Failed to deserialize the first creator
92    #[error("Failed to deserialize the first creator")]
93    InvalidFirstCreator,
94
95    /// 21 - Incorrect account owner
96    #[error("Incorrect account owner")]
97    IncorrectOwner,
98
99    /// 22 Derived key invalid
100    #[error("Derived key invalid")]
101    DerivedKeyInvalid,
102
103    /// 23 - Public key does not match expected value
104    #[error("Public key does not match expected value")]
105    KeyMismatch,
106}
107
108impl From<TrifleError> for ProgramError {
109    fn from(e: TrifleError) -> Self {
110        ProgramError::Custom(e as u32)
111    }
112}
113
114impl PrintProgramError for TrifleError {
115    fn print<E>(&self) {
116        msg!(&self.to_string());
117    }
118}
119
120impl<T> DecodeError<T> for TrifleError {
121    fn type_of() -> &'static str {
122        "Metadata Error"
123    }
124}