apl_token_metadata/
error.rs1use {
4 arch_program::{
5 decode_error::DecodeError,
6 msg,
7 program_error::{PrintProgramError, ProgramError},
8 },
9 num_derive::FromPrimitive,
10 thiserror::Error,
11};
12
13#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)]
15pub enum MetadataError {
16 #[error("Invalid mint")]
19 InvalidMint,
20 #[error("Metadata already exists")]
22 MetadataAlreadyExists,
23 #[error("Metadata not found")]
25 MetadataNotFound,
26 #[error("Invalid authority")]
28 InvalidAuthority,
29 #[error("Invalid instruction data")]
31 InvalidInstructionData,
32 #[error("String too long")]
34 StringTooLong,
35 #[error("Too many attributes")]
37 TooManyAttributes,
38}
39
40impl From<MetadataError> for ProgramError {
41 fn from(e: MetadataError) -> Self {
42 ProgramError::Custom(e as u32)
43 }
44}
45
46impl<T> DecodeError<T> for MetadataError {
47 fn type_of() -> &'static str {
48 "MetadataError"
49 }
50}
51
52impl PrintProgramError for MetadataError {
53 fn print<E>(&self)
54 where
55 E: 'static
56 + std::error::Error
57 + DecodeError<E>
58 + PrintProgramError
59 + num_traits::FromPrimitive,
60 {
61 match self {
62 MetadataError::InvalidMint => msg!("Error: Invalid mint"),
63 MetadataError::MetadataAlreadyExists => msg!("Error: Metadata already exists"),
64 MetadataError::MetadataNotFound => msg!("Error: Metadata not found"),
65 MetadataError::InvalidAuthority => msg!("Error: Invalid authority"),
66 MetadataError::InvalidInstructionData => msg!("Error: Invalid instruction data"),
67 MetadataError::StringTooLong => msg!("Error: String too long"),
68 MetadataError::TooManyAttributes => msg!("Error: Too many attributes"),
69 }
70 }
71}