mpl_token_auth_rules/
error.rs

1//! Errors used by the Rule Set program.
2use num_derive::FromPrimitive;
3use solana_program::{
4    decode_error::DecodeError,
5    msg,
6    program_error::{PrintProgramError, ProgramError},
7};
8use thiserror::Error;
9
10#[derive(Error, Clone, Debug, Eq, PartialEq, FromPrimitive)]
11/// The various errors that can be returned by the Rule Set program instructions.
12pub enum RuleSetError {
13    /// 0 - Numerical Overflow
14    #[error("Numerical Overflow")]
15    NumericalOverflow,
16
17    /// 1 - Data type mismatch
18    #[error("Data type mismatch")]
19    DataTypeMismatch,
20
21    /// 2 - Data slice unexpected index error
22    #[error("Data slice unexpected index error")]
23    DataSliceUnexpectedIndexError,
24
25    /// 3 - Incorrect account owner
26    #[error("Incorrect account owner")]
27    IncorrectOwner,
28
29    /// 4 - PayloadVec Index error.
30    #[error("Could not index into PayloadVec")]
31    PayloadVecIndexError,
32
33    /// 5 - Derived key invalid
34    #[error("Derived key invalid")]
35    DerivedKeyInvalid,
36
37    /// 6 - Payer is not a signer
38    #[error("Payer is not a signer")]
39    PayerIsNotSigner,
40
41    /// 7 - Feature is not implemented yet
42    #[error("Not implemented")]
43    NotImplemented,
44
45    /// 8 - Borsh serialization error
46    #[error("Borsh serialization error")]
47    BorshSerializationError,
48
49    /// 9 - Borsh deserialization error
50    #[error("Borsh deserialization error")]
51    BorshDeserializationError,
52
53    /// 10 - Value in Payload or RuleSet is occupied
54    #[error("Value in Payload or RuleSet is occupied")]
55    ValueOccupied,
56
57    /// 11 - Account data is empty
58    #[error("Account data is empty")]
59    DataIsEmpty,
60
61    /// 12 - MessagePack serialization error
62    #[error("MessagePack serialization error")]
63    MessagePackSerializationError,
64
65    /// 13 - MessagePack deserialization error
66    #[error("MessagePack deserialization error")]
67    MessagePackDeserializationError,
68
69    /// 14 - Missing account
70    #[error("Missing account")]
71    MissingAccount,
72
73    /// 15 - Missing Payload value
74    #[error("Missing Payload value")]
75    MissingPayloadValue,
76
77    /// 16 - RuleSet owner must be payer
78    #[error("RuleSet owner must be payer")]
79    RuleSetOwnerMismatch,
80
81    /// 17 - Name too long
82    #[error("Name too long")]
83    NameTooLong,
84
85    /// 18 - The operation retrieved is not in the selected RuleSet
86    #[error("The operation retrieved is not in the selected RuleSet")]
87    OperationNotFound,
88
89    /// 19 - Rule authority is not signer
90    #[error("Rule authority is not signer")]
91    RuleAuthorityIsNotSigner,
92
93    /// 20 - Unsupported RuleSet header version
94    #[error("Unsupported RuleSet revision map version")]
95    UnsupportedRuleSetRevMapVersion,
96
97    /// 21 - Unsupported RuleSet version
98    #[error("Unsupported RuleSet version")]
99    UnsupportedRuleSetVersion,
100
101    /// 22 - Unexpected RuleSet failure
102    #[error("Unexpected RuleSet failure")]
103    UnexpectedRuleSetFailure,
104
105    /// 23 - RuleSet revision not available
106    #[error("RuleSet revision not available")]
107    RuleSetRevisionNotAvailable,
108
109    /// 24 - Additional Signer check failed
110    #[error("Additional Signer check failed")]
111    AdditionalSignerCheckFailed,
112
113    /// 25 - Pubkey Match check failed
114    #[error("Pubkey Match check failed")]
115    PubkeyMatchCheckFailed,
116
117    /// 26 - Pubkey List Match check failed
118    #[error("Pubkey List Match check failed")]
119    PubkeyListMatchCheckFailed,
120
121    /// 27 - Pubkey Tree Match check failed
122    #[error("Pubkey Tree Match check failed")]
123    PubkeyTreeMatchCheckFailed,
124
125    /// 28 - PDA Match check failed
126    #[error("PDA Match check failed")]
127    PDAMatchCheckFailed,
128
129    /// 29 - Program Owned check failed
130    #[error("Program Owned check failed")]
131    ProgramOwnedCheckFailed,
132
133    /// 30 - Program Owned List check failed
134    #[error("Program Owned List check failed")]
135    ProgramOwnedListCheckFailed,
136
137    /// 31 - Program Owned Tree check failed
138    #[error("Program Owned Tree check failed")]
139    ProgramOwnedTreeCheckFailed,
140
141    /// 32 - Amount checked failed
142    #[error("Amount checked failed")]
143    AmountCheckFailed,
144
145    /// 33 - Frequency check failed
146    #[error("Frequency check failed")]
147    FrequencyCheckFailed,
148
149    /// 34 - IsWallet check failed
150    #[error("IsWallet check failed")]
151    IsWalletCheckFailed,
152
153    /// 35 - Program Owned Set check failed
154    #[error("Program Owned Set check failed")]
155    ProgramOwnedSetCheckFailed,
156
157    /// 36 - Invalid compare operator
158    #[error("Invalid compare operator")]
159    InvalidCompareOp,
160
161    /// 37 - Invalid constraint type value
162    #[error("Invalid constraint type value")]
163    InvalidConstraintType,
164
165    /// 38 - Deserialization error
166    #[error("Failed to read the rule set")]
167    RuleSetReadFailed,
168
169    /// 39 - Duplicated operation name
170    #[error("Duplicated operation name")]
171    DuplicatedOperationName,
172
173    /// 40 - Could not determine alignemnt
174    #[error("Could not determine alignemnt")]
175    AlignmentError,
176}
177
178impl PrintProgramError for RuleSetError {
179    fn print<E>(&self) {
180        msg!(&self.to_string());
181    }
182}
183
184impl From<RuleSetError> for ProgramError {
185    fn from(e: RuleSetError) -> Self {
186        ProgramError::Custom(e as u32)
187    }
188}
189
190impl<T> DecodeError<T> for RuleSetError {
191    fn type_of() -> &'static str {
192        "Error Thingy"
193    }
194}