spl_tlv_account_resolution/
error.rs

1//! 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 Account Resolution library.
10#[repr(u32)]
11#[derive(Clone, Debug, Eq, thiserror::Error, num_derive::FromPrimitive, PartialEq)]
12pub enum AccountResolutionError {
13    /// Incorrect account provided
14    #[error("Incorrect account provided")]
15    IncorrectAccount = 2_724_315_840,
16    /// Not enough accounts provided
17    #[error("Not enough accounts provided")]
18    NotEnoughAccounts,
19    /// No value initialized in TLV data
20    #[error("No value initialized in TLV data")]
21    TlvUninitialized,
22    /// Some value initialized in TLV data
23    #[error("Some value initialized in TLV data")]
24    TlvInitialized,
25    /// Too many pubkeys provided
26    #[error("Too many pubkeys provided")]
27    TooManyPubkeys,
28    /// Failed to parse `Pubkey` from bytes
29    #[error("Failed to parse `Pubkey` from bytes")]
30    InvalidPubkey,
31    /// Attempted to deserialize an `AccountMeta` but the underlying type has
32    /// PDA configurations rather than a fixed address
33    #[error(
34        "Attempted to deserialize an `AccountMeta` but the underlying type has PDA configurations rather \
35         than a fixed address"
36    )]
37    AccountTypeNotAccountMeta,
38    /// Provided list of seed configurations too large for a validation account
39    #[error("Provided list of seed configurations too large for a validation account")]
40    SeedConfigsTooLarge,
41    /// Not enough bytes available to pack seed configuration
42    #[error("Not enough bytes available to pack seed configuration")]
43    NotEnoughBytesForSeed,
44    /// The provided bytes are not valid for a seed configuration
45    #[error("The provided bytes are not valid for a seed configuration")]
46    InvalidBytesForSeed,
47    /// Tried to pack an invalid seed configuration
48    #[error("Tried to pack an invalid seed configuration")]
49    InvalidSeedConfig,
50    /// Instruction data too small for seed configuration
51    #[error("Instruction data too small for seed configuration")]
52    InstructionDataTooSmall,
53    /// Could not find account at specified index
54    #[error("Could not find account at specified index")]
55    AccountNotFound,
56    /// Error in checked math operation
57    #[error("Error in checked math operation")]
58    CalculationFailure,
59    /// Could not find account data at specified index
60    #[error("Could not find account data at specified index")]
61    AccountDataNotFound,
62    /// Account data too small for requested seed configuration
63    #[error("Account data too small for requested seed configuration")]
64    AccountDataTooSmall,
65    /// Failed to fetch account
66    #[error("Failed to fetch account")]
67    AccountFetchFailed,
68    /// Not enough bytes available to pack pubkey data configuration.
69    #[error("Not enough bytes available to pack pubkey data configuration")]
70    NotEnoughBytesForPubkeyData,
71    /// The provided bytes are not valid for a pubkey data configuration
72    #[error("The provided bytes are not valid for a pubkey data configuration")]
73    InvalidBytesForPubkeyData,
74    /// Tried to pack an invalid pubkey data configuration
75    #[error("Tried to pack an invalid pubkey data configuration")]
76    InvalidPubkeyDataConfig,
77}
78
79impl From<AccountResolutionError> for ProgramError {
80    fn from(e: AccountResolutionError) -> Self {
81        ProgramError::Custom(e as u32)
82    }
83}
84
85impl<T> DecodeError<T> for AccountResolutionError {
86    fn type_of() -> &'static str {
87        "AccountResolutionError"
88    }
89}
90
91impl PrintProgramError for AccountResolutionError {
92    fn print<E>(&self)
93    where
94        E: 'static
95            + std::error::Error
96            + DecodeError<E>
97            + PrintProgramError
98            + num_traits::FromPrimitive,
99    {
100        match self {
101            AccountResolutionError::IncorrectAccount => {
102                msg!("Incorrect account provided")
103            }
104            AccountResolutionError::NotEnoughAccounts => {
105                msg!("Not enough accounts provided")
106            }
107            AccountResolutionError::TlvUninitialized => {
108                msg!("No value initialized in TLV data")
109            }
110            AccountResolutionError::TlvInitialized => {
111                msg!("Some value initialized in TLV data")
112            }
113            AccountResolutionError::TooManyPubkeys => {
114                msg!("Too many pubkeys provided")
115            }
116            AccountResolutionError::InvalidPubkey => {
117                msg!("Failed to parse `Pubkey` from bytes")
118            }
119            AccountResolutionError::AccountTypeNotAccountMeta => {
120                msg!(
121                    "Attempted to deserialize an `AccountMeta` but the underlying type has PDA configs rather than a fixed address",
122                )
123            }
124            AccountResolutionError::SeedConfigsTooLarge => {
125                msg!("Provided list of seed configurations too large for a validation account",)
126            }
127            AccountResolutionError::NotEnoughBytesForSeed => {
128                msg!("Not enough bytes available to pack seed configuration",)
129            }
130            AccountResolutionError::InvalidBytesForSeed => {
131                msg!("The provided bytes are not valid for a seed configuration",)
132            }
133            AccountResolutionError::InvalidSeedConfig => {
134                msg!("Tried to pack an invalid seed configuration",)
135            }
136            AccountResolutionError::InstructionDataTooSmall => {
137                msg!("Instruction data too small for seed configuration",)
138            }
139            AccountResolutionError::AccountNotFound => {
140                msg!("Could not find account at specified index",)
141            }
142            AccountResolutionError::CalculationFailure => {
143                msg!("Error in checked math operation")
144            }
145            AccountResolutionError::AccountDataNotFound => {
146                msg!("Could not find account data at specified index",)
147            }
148            AccountResolutionError::AccountDataTooSmall => {
149                msg!("Account data too small for requested seed configuration",)
150            }
151            AccountResolutionError::AccountFetchFailed => {
152                msg!("Failed to fetch account")
153            }
154            AccountResolutionError::NotEnoughBytesForPubkeyData => {
155                msg!("Not enough bytes available to pack pubkey data configuration",)
156            }
157            AccountResolutionError::InvalidBytesForPubkeyData => {
158                msg!("The provided bytes are not valid for a pubkey data configuration",)
159            }
160            AccountResolutionError::InvalidPubkeyDataConfig => {
161                msg!("Tried to pack an invalid pubkey data configuration",)
162            }
163        }
164    }
165}