1use num_derive::FromPrimitive;
2use solana_program::{
3 decode_error::DecodeError,
4 msg,
5 program_error::{PrintProgramError, ProgramError},
6};
7use thiserror::Error;
8
9#[derive(Error, Clone, Debug, Eq, PartialEq, FromPrimitive)]
10pub enum OnchainMetadataError {
11 #[error("The account has already been initialized")]
13 AlreadyInitialized,
14
15 #[error("The account has not yet been initialized")]
17 NotInitialized,
18
19 #[error("The key for the JSON metadata account is invalid.")]
20 MetadataDerivedKeyInvalid,
21
22 #[error("The system program account is invalid.")]
23 InvalidSystemProgram,
24
25 #[error("The JSON data is invalid.")]
26 InvalidJson,
27
28 #[error("Borsh failed to serialize this account.")]
29 BorshSerializeError,
30
31 #[error("The payer does not have authority to perform this action.")]
32 InvalidAuthority,
33}
34
35impl PrintProgramError for OnchainMetadataError {
36 fn print<E>(&self) {
37 msg!(&self.to_string());
38 }
39}
40
41impl From<OnchainMetadataError> for ProgramError {
42 fn from(e: OnchainMetadataError) -> Self {
43 ProgramError::Custom(e as u32)
44 }
45}
46
47impl<T> DecodeError<T> for OnchainMetadataError {
48 fn type_of() -> &'static str {
49 "Error Thingy"
50 }
51}