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 #[error("Numerical Overflow")]
13 NumericalOverflow,
14
15 #[error("Invalid account")]
17 InvalidAccount,
18
19 #[error("Invalid Escrow Constraint Model")]
21 InvalidEscrowConstraintModel,
22
23 #[error("Invalid Escrow Constraint")]
25 InvalidEscrowConstraint,
26
27 #[error("Escrow Constraint Violation")]
29 EscrowConstraintViolation,
30
31 #[error("Invalid Update Authority")]
33 InvalidUpdateAuthority,
34
35 #[error("Failed to create pubkey")]
37 FailedToCreatePubkey,
38
39 #[error("Data type mismatch")]
41 DataTypeMismatch,
42
43 #[error("Constraint already exists")]
45 ConstraintAlreadyExists,
46
47 #[error("Token Limit Exceeded")]
49 TokenLimitExceeded,
50
51 #[error("Failed to find Token Amount")]
53 FailedToFindTokenAmount,
54
55 #[error("Invalid Collection Metadata")]
57 InvalidCollectionMetadata,
58
59 #[error("Provided Transfer Effects are not compatible")]
61 TransferEffectConflict,
62
63 #[error("Freeze Authority Not Set")]
65 FreezeAuthorityNotSet,
66
67 #[error("Cannot burn Print Edition")]
69 CannotBurnPrintEdition,
70
71 #[error("Constraint Key Not Found")]
73 ConstraintKeyNotFound,
74
75 #[error("Failed to serialize")]
77 FailedToSerialize,
78
79 #[error("Failed to borrow account data")]
81 FailedToBorrowAccountData,
82
83 #[error("Failed to deserialize collection")]
85 InvalidCollection,
86
87 #[error("Only the holder is allowed to perform this action")]
89 MustBeHolder,
90
91 #[error("Failed to deserialize the first creator")]
93 InvalidFirstCreator,
94
95 #[error("Incorrect account owner")]
97 IncorrectOwner,
98
99 #[error("Derived key invalid")]
101 DerivedKeyInvalid,
102
103 #[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}