|
1 | 1 | //! Error types |
2 | 2 |
|
3 | | -use spl_program_error::*; |
| 3 | +use { |
| 4 | + solana_decode_error::DecodeError, |
| 5 | + solana_msg::msg, |
| 6 | + solana_program_error::{PrintProgramError, ProgramError}, |
| 7 | +}; |
4 | 8 |
|
5 | 9 | /// Errors that may be returned by the Account Resolution library. |
6 | | -#[spl_program_error(hash_error_code_start = 2_724_315_840)] |
| 10 | +#[repr(u32)] |
| 11 | +#[derive(Clone, Debug, Eq, thiserror::Error, num_derive::FromPrimitive, PartialEq)] |
7 | 12 | pub enum AccountResolutionError { |
8 | 13 | /// Incorrect account provided |
9 | 14 | #[error("Incorrect account provided")] |
10 | | - IncorrectAccount, |
| 15 | + IncorrectAccount = 2_724_315_840, |
11 | 16 | /// Not enough accounts provided |
12 | 17 | #[error("Not enough accounts provided")] |
13 | 18 | NotEnoughAccounts, |
@@ -70,3 +75,91 @@ pub enum AccountResolutionError { |
70 | 75 | #[error("Tried to pack an invalid pubkey data configuration")] |
71 | 76 | InvalidPubkeyDataConfig, |
72 | 77 | } |
| 78 | + |
| 79 | +impl From<AccountResolutionError> for ProgramError { |
| 80 | + fn from(e: AccountResolutionError) -> Self { |
| 81 | + ProgramError::Custom(e as u32) |
| 82 | + } |
| 83 | +} |
| 84 | + |
| 85 | +impl<T> DecodeError<T> for AccountResolutionError { |
| 86 | + fn type_of() -> &'static str { |
| 87 | + "AccountResolutionError" |
| 88 | + } |
| 89 | +} |
| 90 | + |
| 91 | +impl 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 | +} |
0 commit comments