spl_token_metadata_interface/
error.rs

1//! Interface error types
2
3use {
4    solana_decode_error::DecodeError,
5    solana_msg::msg,
6    solana_program_error::{PrintProgramError, ProgramError},
7};
8
9/// Errors that may be returned by the interface.
10#[repr(u32)]
11#[derive(Clone, Debug, Eq, thiserror::Error, num_derive::FromPrimitive, PartialEq)]
12pub enum TokenMetadataError {
13    /// Incorrect account provided
14    #[error("Incorrect account provided")]
15    IncorrectAccount = 901_952_957,
16    /// Mint has no mint authority
17    #[error("Mint has no mint authority")]
18    MintHasNoMintAuthority,
19    /// Incorrect mint authority has signed the instruction
20    #[error("Incorrect mint authority has signed the instruction")]
21    IncorrectMintAuthority,
22    /// Incorrect metadata update authority has signed the instruction
23    #[error("Incorrect metadata update authority has signed the instruction")]
24    IncorrectUpdateAuthority,
25    /// Token metadata has no update authority
26    #[error("Token metadata has no update authority")]
27    ImmutableMetadata,
28    /// Key not found in metadata account
29    #[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}