spl_token_metadata_interface/
error.rs1use {
4 solana_decode_error::DecodeError,
5 solana_msg::msg,
6 solana_program_error::{PrintProgramError, ProgramError},
7};
8
9#[repr(u32)]
11#[derive(Clone, Debug, Eq, thiserror::Error, num_derive::FromPrimitive, PartialEq)]
12pub enum TokenMetadataError {
13 #[error("Incorrect account provided")]
15 IncorrectAccount = 901_952_957,
16 #[error("Mint has no mint authority")]
18 MintHasNoMintAuthority,
19 #[error("Incorrect mint authority has signed the instruction")]
21 IncorrectMintAuthority,
22 #[error("Incorrect metadata update authority has signed the instruction")]
24 IncorrectUpdateAuthority,
25 #[error("Token metadata has no update authority")]
27 ImmutableMetadata,
28 #[error("Key not found in metadata account")]
30 KeyNotFound,
31}
32
33impl From<TokenMetadataError> for ProgramError {
34 fn from(e: TokenMetadataError) -> Self {
35 ProgramError::Custom(e as u32)
36 }
37}
38
39impl<T> DecodeError<T> for TokenMetadataError {
40 fn type_of() -> &'static str {
41 "TokenMetadataError"
42 }
43}
44
45impl PrintProgramError for TokenMetadataError {
46 fn print<E>(&self)
47 where
48 E: 'static
49 + std::error::Error
50 + DecodeError<E>
51 + PrintProgramError
52 + num_traits::FromPrimitive,
53 {
54 match self {
55 TokenMetadataError::IncorrectAccount => {
56 msg!("Incorrect account provided")
57 }
58 TokenMetadataError::MintHasNoMintAuthority => {
59 msg!("Mint has no mint authority")
60 }
61 TokenMetadataError::IncorrectMintAuthority => {
62 msg!("Incorrect mint authority has signed the instruction",)
63 }
64 TokenMetadataError::IncorrectUpdateAuthority => {
65 msg!("Incorrect metadata update authority has signed the instruction",)
66 }
67 TokenMetadataError::ImmutableMetadata => {
68 msg!("Token metadata has no update authority")
69 }
70 TokenMetadataError::KeyNotFound => {
71 msg!("Key not found in metadata account")
72 }
73 }
74 }
75}