Skip to main content

spl_token_metadata_interface/
error.rs

1//! Interface error types
2
3use solana_program_error::{ProgramError, ToStr};
4
5/// Errors that may be returned by the interface.
6#[repr(u32)]
7#[derive(
8    Clone,
9    Debug,
10    Eq,
11    thiserror::Error,
12    num_derive::FromPrimitive,
13    num_enum::TryFromPrimitive,
14    PartialEq,
15)]
16pub enum TokenMetadataError {
17    /// Incorrect account provided
18    #[error("Incorrect account provided")]
19    IncorrectAccount = 901_952_957,
20    /// Mint has no mint authority
21    #[error("Mint has no mint authority")]
22    MintHasNoMintAuthority,
23    /// Incorrect mint authority has signed the instruction
24    #[error("Incorrect mint authority has signed the instruction")]
25    IncorrectMintAuthority,
26    /// Incorrect metadata update authority has signed the instruction
27    #[error("Incorrect metadata update authority has signed the instruction")]
28    IncorrectUpdateAuthority,
29    /// Token metadata has no update authority
30    #[error("Token metadata has no update authority")]
31    ImmutableMetadata,
32    /// Key not found in metadata account
33    #[error("Key not found in metadata account")]
34    KeyNotFound,
35}
36
37impl From<TokenMetadataError> for ProgramError {
38    fn from(e: TokenMetadataError) -> Self {
39        ProgramError::Custom(e as u32)
40    }
41}
42
43impl ToStr for TokenMetadataError {
44    fn to_str(&self) -> &'static str {
45        match self {
46            TokenMetadataError::IncorrectAccount => "Incorrect account provided",
47            TokenMetadataError::MintHasNoMintAuthority => "Mint has no mint authority",
48            TokenMetadataError::IncorrectMintAuthority => {
49                "Incorrect mint authority has signed the instruction"
50            }
51            TokenMetadataError::IncorrectUpdateAuthority => {
52                "Incorrect metadata update authority has signed the instruction"
53            }
54            TokenMetadataError::ImmutableMetadata => "Token metadata has no update authority",
55            TokenMetadataError::KeyNotFound => "Key not found in metadata account",
56        }
57    }
58}