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(Clone, Debug, Eq, thiserror::Error, num_derive::FromPrimitive, PartialEq)]
8pub enum TokenMetadataError {
9    /// Incorrect account provided
10    #[error("Incorrect account provided")]
11    IncorrectAccount = 901_952_957,
12    /// Mint has no mint authority
13    #[error("Mint has no mint authority")]
14    MintHasNoMintAuthority,
15    /// Incorrect mint authority has signed the instruction
16    #[error("Incorrect mint authority has signed the instruction")]
17    IncorrectMintAuthority,
18    /// Incorrect metadata update authority has signed the instruction
19    #[error("Incorrect metadata update authority has signed the instruction")]
20    IncorrectUpdateAuthority,
21    /// Token metadata has no update authority
22    #[error("Token metadata has no update authority")]
23    ImmutableMetadata,
24    /// Key not found in metadata account
25    #[error("Key not found in metadata account")]
26    KeyNotFound,
27}
28
29impl From<TokenMetadataError> for ProgramError {
30    fn from(e: TokenMetadataError) -> Self {
31        ProgramError::Custom(e as u32)
32    }
33}
34
35impl ToStr for TokenMetadataError {
36    fn to_str(&self) -> &'static str {
37        match self {
38            TokenMetadataError::IncorrectAccount => "Incorrect account provided",
39            TokenMetadataError::MintHasNoMintAuthority => "Mint has no mint authority",
40            TokenMetadataError::IncorrectMintAuthority => {
41                "Incorrect mint authority has signed the instruction"
42            }
43            TokenMetadataError::IncorrectUpdateAuthority => {
44                "Incorrect metadata update authority has signed the instruction"
45            }
46            TokenMetadataError::ImmutableMetadata => "Token metadata has no update authority",
47            TokenMetadataError::KeyNotFound => "Key not found in metadata account",
48        }
49    }
50}