Skip to main content

solana_nft_token_metadata/
error.rs

1//! Error types
2
3use num_derive::FromPrimitive;
4use solana_program::{
5    decode_error::DecodeError,
6    msg,
7    program_error::{PrintProgramError, ProgramError},
8};
9use thiserror::Error;
10
11/// Errors that may be returned by the Metadata program.
12#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)]
13pub enum MetadataError {
14    /// Failed to unpack instruction data
15    #[error("Failed to unpack instruction data")]
16    InstructionUnpackError,
17
18    /// Failed to pack instruction data
19    #[error("Failed to pack instruction data")]
20    InstructionPackError,
21
22    /// Lamport balance below rent-exempt threshold.
23    #[error("Lamport balance below rent-exempt threshold")]
24    NotRentExempt,
25
26    /// Already initialized
27    #[error("Already initialized")]
28    AlreadyInitialized,
29
30    /// Uninitialized
31    #[error("Uninitialized")]
32    Uninitialized,
33
34    ///  Metadata's key must match seed of ['metadata', program id, mint] provided
35    #[error(" Metadata's key must match seed of ['metadata', program id, mint] provided")]
36    InvalidMetadataKey,
37
38    ///  Edition's key must match seed of ['metadata', program id, name, 'edition'] provided
39    #[error("Edition's key must match seed of ['metadata', program id, name, 'edition'] provided")]
40    InvalidEditionKey,
41
42    /// Update Authority given does not match
43    #[error("Update Authority given does not match")]
44    UpdateAuthorityIncorrect,
45
46    /// Update Authority needs to be signer to update  metadata
47    #[error("Update Authority needs to be signer to update metadata")]
48    UpdateAuthorityIsNotSigner,
49
50    /// You must be the mint authority and signer on this transaction
51    #[error("You must be the mint authority and signer on this transaction")]
52    NotMintAuthority,
53
54    /// Mint authority provided does not match the authority on the mint
55    #[error("Mint authority provided does not match the authority on the mint")]
56    InvalidMintAuthority,
57
58    /// Name too long
59    #[error("Name too long")]
60    NameTooLong,
61
62    /// Symbol too long
63    #[error("Symbol too long")]
64    SymbolTooLong,
65
66    /// URI too long
67    #[error("URI too long")]
68    UriTooLong,
69
70    /// Update authority must be equivalent to the metadata's authority and also signer of this transaction
71    #[error("Update authority must be equivalent to the metadata's authority and also signer of this transaction")]
72    UpdateAuthorityMustBeEqualToMetadataAuthorityAndSigner,
73
74    /// Mint given does not match mint on Metadata
75    #[error("Mint given does not match mint on Metadata")]
76    MintMismatch,
77
78    /// Editions must have exactly one token
79    #[error("Editions must have exactly one token")]
80    EditionsMustHaveExactlyOneToken,
81
82    /// Maximum editions printed already
83    #[error("Maximum editions printed already")]
84    MaxEditionsMintedAlready,
85
86    /// Token mint to failed
87    #[error("Token mint to failed")]
88    TokenMintToFailed,
89
90    /// The master edition record passed must match the master record on the edition given
91    #[error("The master edition record passed must match the master record on the edition given")]
92    MasterRecordMismatch,
93
94    /// The destination account does not have the right mint
95    #[error("The destination account does not have the right mint")]
96    DestinationMintMismatch,
97
98    /// An edition can only mint one of its kind!
99    #[error("An edition can only mint one of its kind!")]
100    EditionAlreadyMinted,
101
102    /// Printing mint decimals should be zero
103    #[error("Printing mint decimals should be zero")]
104    PrintingMintDecimalsShouldBeZero,
105
106    /// OneTimePrintingAuthorizationMint mint decimals should be zero
107    #[error("OneTimePrintingAuthorization mint decimals should be zero")]
108    OneTimePrintingAuthorizationMintDecimalsShouldBeZero,
109
110    /// Edition mint decimals should be zero
111    #[error("EditionMintDecimalsShouldBeZero")]
112    EditionMintDecimalsShouldBeZero,
113
114    /// Token burn failed
115    #[error("Token burn failed")]
116    TokenBurnFailed,
117
118    /// The One Time authorization mint does not match that on the token account!
119    #[error("The One Time authorization mint does not match that on the token account!")]
120    TokenAccountOneTimeAuthMintMismatch,
121
122    /// Derived key invalid
123    #[error("Derived key invalid")]
124    DerivedKeyInvalid,
125
126    /// The Printing mint does not match that on the master edition!
127    #[error("The Printing mint does not match that on the master edition!")]
128    PrintingMintMismatch,
129
130    /// The  One Time Printing Auth mint does not match that on the master edition!
131    #[error("The One Time Printing Auth mint does not match that on the master edition!")]
132    OneTimePrintingAuthMintMismatch,
133
134    /// The mint of the token account does not match the Printing mint!
135    #[error("The mint of the token account does not match the Printing mint!")]
136    TokenAccountMintMismatch,
137
138    /// The mint of the token account does not match the master metadata mint!
139    #[error("The mint of the token account does not match the master metadata mint!")]
140    TokenAccountMintMismatchV2,
141
142    /// Not enough tokens to mint a limited edition
143    #[error("Not enough tokens to mint a limited edition")]
144    NotEnoughTokens,
145
146    /// The mint on your authorization token holding account does not match your Printing mint!
147    #[error(
148        "The mint on your authorization token holding account does not match your Printing mint!"
149    )]
150    PrintingMintAuthorizationAccountMismatch,
151
152    /// The authorization token account has a different owner than the update authority for the master edition!
153    #[error("The authorization token account has a different owner than the update authority for the master edition!")]
154    AuthorizationTokenAccountOwnerMismatch,
155
156    /// This feature is currently disabled.
157    #[error("This feature is currently disabled.")]
158    Disabled,
159
160    /// Creators list too long
161    #[error("Creators list too long")]
162    CreatorsTooLong,
163
164    /// Creators must be at least one if set
165    #[error("Creators must be at least one if set")]
166    CreatorsMustBeAtleastOne,
167
168    /// If using a creators array, you must be one of the creators listed
169    #[error("If using a creators array, you must be one of the creators listed")]
170    MustBeOneOfCreators,
171
172    /// This metadata does not have creators
173    #[error("This metadata does not have creators")]
174    NoCreatorsPresentOnMetadata,
175
176    /// This creator address was not found
177    #[error("This creator address was not found")]
178    CreatorNotFound,
179
180    /// Basis points cannot be more than 10000
181    #[error("Basis points cannot be more than 10000")]
182    InvalidBasisPoints,
183
184    /// Primary sale can only be flipped to true and is immutable
185    #[error("Primary sale can only be flipped to true and is immutable")]
186    PrimarySaleCanOnlyBeFlippedToTrue,
187
188    /// Owner does not match that on the account given
189    #[error("Owner does not match that on the account given")]
190    OwnerMismatch,
191
192    /// This account has no tokens to be used for authorization
193    #[error("This account has no tokens to be used for authorization")]
194    NoBalanceInAccountForAuthorization,
195
196    /// Share total must equal 100 for creator array
197    #[error("Share total must equal 100 for creator array")]
198    ShareTotalMustBe100,
199
200    /// This reservation list already exists!
201    #[error("This reservation list already exists!")]
202    ReservationExists,
203
204    /// This reservation list does not exist!
205    #[error("This reservation list does not exist!")]
206    ReservationDoesNotExist,
207
208    /// This reservation list exists but was never set with reservations
209    #[error("This reservation list exists but was never set with reservations")]
210    ReservationNotSet,
211
212    /// This reservation list has already been set!
213    #[error("This reservation list has already been set!")]
214    ReservationAlreadyMade,
215
216    /// Provided more addresses than max allowed in single reservation
217    #[error("Provided more addresses than max allowed in single reservation")]
218    BeyondMaxAddressSize,
219
220    /// NumericalOverflowError
221    #[error("NumericalOverflowError")]
222    NumericalOverflowError,
223
224    /// This reservation would go beyond the maximum supply of the master edition!
225    #[error("This reservation would go beyond the maximum supply of the master edition!")]
226    ReservationBreachesMaximumSupply,
227
228    /// Address not in reservation!
229    #[error("Address not in reservation!")]
230    AddressNotInReservation,
231
232    /// You cannot unilaterally verify another creator, they must sign
233    #[error("You cannot unilaterally verify another creator, they must sign")]
234    CannotVerifyAnotherCreator,
235
236    /// You cannot unilaterally unverify another creator
237    #[error("You cannot unilaterally unverify another creator")]
238    CannotUnverifyAnotherCreator,
239
240    /// In initial reservation setting, spots remaining should equal total spots
241    #[error("In initial reservation setting, spots remaining should equal total spots")]
242    SpotMismatch,
243
244    /// Incorrect account owner
245    #[error("Incorrect account owner")]
246    IncorrectOwner,
247
248    /// printing these tokens would breach the maximum supply limit of the master edition
249    #[error("printing these tokens would breach the maximum supply limit of the master edition")]
250    PrintingWouldBreachMaximumSupply,
251
252    /// Data is immutable
253    #[error("Data is immutable")]
254    DataIsImmutable,
255
256    /// No duplicate creator addresses
257    #[error("No duplicate creator addresses")]
258    DuplicateCreatorAddress,
259
260    /// Reservation spots remaining should match total spots when first being created
261    #[error("Reservation spots remaining should match total spots when first being created")]
262    ReservationSpotsRemainingShouldMatchTotalSpotsAtStart,
263
264    /// Invalid token program
265    #[error("Invalid token program")]
266    InvalidTokenProgram,
267
268    /// Data type mismatch
269    #[error("Data type mismatch")]
270    DataTypeMismatch,
271
272    /// Beyond alotted address size in reservation!
273    #[error("Beyond alotted address size in reservation!")]
274    BeyondAlottedAddressSize,
275
276    /// The reservation has only been partially alotted
277    #[error("The reservation has only been partially alotted")]
278    ReservationNotComplete,
279
280    /// You cannot splice over an existing reservation!
281    #[error("You cannot splice over an existing reservation!")]
282    TriedToReplaceAnExistingReservation,
283
284    /// Invalid operation
285    #[error("Invalid operation")]
286    InvalidOperation,
287
288    /// Invalid owner
289    #[error("Invalid Owner")]
290    InvalidOwner,
291
292    /// Printing mint supply must be zero for conversion
293    #[error("Printing mint supply must be zero for conversion")]
294    PrintingMintSupplyMustBeZeroForConversion,
295
296    /// One Time Auth mint supply must be zero for conversion
297    #[error("One Time Auth mint supply must be zero for conversion")]
298    OneTimeAuthMintSupplyMustBeZeroForConversion,
299
300    /// You tried to insert one edition too many into an edition mark pda
301    #[error("You tried to insert one edition too many into an edition mark pda")]
302    InvalidEditionIndex,
303
304    // In the legacy system the reservation needs to be of size one for cpu limit reasons
305    #[error("In the legacy system the reservation needs to be of size one for cpu limit reasons")]
306    ReservationArrayShouldBeSizeOne,
307
308    /// Is Mutable can only be flipped to false
309    #[error("Is Mutable can only be flipped to false")]
310    IsMutableCanOnlyBeFlippedToFalse,
311
312    #[error("Cannont Verify Collection in this Instruction")]
313    CollectionCannotBeVerifiedInThisInstruction,
314
315    #[error("This instruction was deprecated in a previous release and is now removed")]
316    Removed, //For the curious we cannot get rid of an instruction in the enum or move them or it will break our api, this is a friendly way to get rid of them
317
318    #[error("This token use method is burn and there are no remaining uses, it must be burned")]
319    MustBeBurned,
320
321    #[error("This use method is invalid")]
322    InvalidUseMethod,
323    #[error("Cannot Change Use Method after the first use")]
324    CannotChangeUseMethodAfterFirstUse,
325
326    #[error("Cannot Change Remaining or Available uses after the first use")]
327    CannotChangeUsesAfterFirstUse,
328
329    #[error("Collection Not Found on Metadata")]
330    CollectionNotFound,
331
332    #[error("Collection Update Authority is invalid")]
333    InvalidCollectionUpdateAuthority,
334
335    #[error("Collection Must Be a Unique Master Edition v2")]
336    CollectionMustBeAUniqueMasterEdition,
337
338    #[error("The Use Authority Record Already Exists, to modify it Revoke, then Approve")]
339    UseAuthorityRecordAlreadyExists,
340
341    #[error("The Use Authority Record is empty or already revoked")]
342    UseAuthorityRecordAlreadyRevoked,
343
344    #[error("This token has no uses")]
345    Unusable,
346
347    #[error("There are not enough Uses left on this token.")]
348    NotEnoughUses,
349
350    #[error("This Collection Authority Record Already Exists.")]
351    CollectionAuthorityRecordAlreadyExists,
352
353    #[error("This Collection Authoritty Record Does Not Exist.")]
354    CollectionAuthorityDoesNotExist,
355}
356
357impl PrintProgramError for MetadataError {
358    fn print<E>(&self) {
359        msg!(&self.to_string());
360    }
361}
362
363impl From<MetadataError> for ProgramError {
364    fn from(e: MetadataError) -> Self {
365        ProgramError::Custom(e as u32)
366    }
367}
368
369impl<T> DecodeError<T> for MetadataError {
370    fn type_of() -> &'static str {
371        "Metadata Error"
372    }
373}