spl_tlv_account_resolution/
error.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
//! Error types

use {
    solana_decode_error::DecodeError,
    solana_msg::msg,
    solana_program_error::{PrintProgramError, ProgramError},
};

/// Errors that may be returned by the Account Resolution library.
#[repr(u32)]
#[derive(Clone, Debug, Eq, thiserror::Error, num_derive::FromPrimitive, PartialEq)]
pub enum AccountResolutionError {
    /// Incorrect account provided
    #[error("Incorrect account provided")]
    IncorrectAccount = 2_724_315_840,
    /// Not enough accounts provided
    #[error("Not enough accounts provided")]
    NotEnoughAccounts,
    /// No value initialized in TLV data
    #[error("No value initialized in TLV data")]
    TlvUninitialized,
    /// Some value initialized in TLV data
    #[error("Some value initialized in TLV data")]
    TlvInitialized,
    /// Too many pubkeys provided
    #[error("Too many pubkeys provided")]
    TooManyPubkeys,
    /// Failed to parse `Pubkey` from bytes
    #[error("Failed to parse `Pubkey` from bytes")]
    InvalidPubkey,
    /// Attempted to deserialize an `AccountMeta` but the underlying type has
    /// PDA configs rather than a fixed address
    #[error(
        "Attempted to deserialize an `AccountMeta` but the underlying type has PDA configs rather \
         than a fixed address"
    )]
    AccountTypeNotAccountMeta,
    /// Provided list of seed configurations too large for a validation account
    #[error("Provided list of seed configurations too large for a validation account")]
    SeedConfigsTooLarge,
    /// Not enough bytes available to pack seed configuration
    #[error("Not enough bytes available to pack seed configuration")]
    NotEnoughBytesForSeed,
    /// The provided bytes are not valid for a seed configuration
    #[error("The provided bytes are not valid for a seed configuration")]
    InvalidBytesForSeed,
    /// Tried to pack an invalid seed configuration
    #[error("Tried to pack an invalid seed configuration")]
    InvalidSeedConfig,
    /// Instruction data too small for seed configuration
    #[error("Instruction data too small for seed configuration")]
    InstructionDataTooSmall,
    /// Could not find account at specified index
    #[error("Could not find account at specified index")]
    AccountNotFound,
    /// Error in checked math operation
    #[error("Error in checked math operation")]
    CalculationFailure,
    /// Could not find account data at specified index
    #[error("Could not find account data at specified index")]
    AccountDataNotFound,
    /// Account data too small for requested seed configuration
    #[error("Account data too small for requested seed configuration")]
    AccountDataTooSmall,
    /// Failed to fetch account
    #[error("Failed to fetch account")]
    AccountFetchFailed,
    /// Not enough bytes available to pack pubkey data configuration.
    #[error("Not enough bytes available to pack pubkey data configuration")]
    NotEnoughBytesForPubkeyData,
    /// The provided bytes are not valid for a pubkey data configuration
    #[error("The provided bytes are not valid for a pubkey data configuration")]
    InvalidBytesForPubkeyData,
    /// Tried to pack an invalid pubkey data configuration
    #[error("Tried to pack an invalid pubkey data configuration")]
    InvalidPubkeyDataConfig,
}

impl From<AccountResolutionError> for ProgramError {
    fn from(e: AccountResolutionError) -> Self {
        ProgramError::Custom(e as u32)
    }
}

impl<T> DecodeError<T> for AccountResolutionError {
    fn type_of() -> &'static str {
        "AccountResolutionError"
    }
}

impl PrintProgramError for AccountResolutionError {
    fn print<E>(&self)
    where
        E: 'static
            + std::error::Error
            + DecodeError<E>
            + PrintProgramError
            + num_traits::FromPrimitive,
    {
        match self {
            AccountResolutionError::IncorrectAccount => {
                msg!("Incorrect account provided")
            }
            AccountResolutionError::NotEnoughAccounts => {
                msg!("Not enough accounts provided")
            }
            AccountResolutionError::TlvUninitialized => {
                msg!("No value initialized in TLV data")
            }
            AccountResolutionError::TlvInitialized => {
                msg!("Some value initialized in TLV data")
            }
            AccountResolutionError::TooManyPubkeys => {
                msg!("Too many pubkeys provided")
            }
            AccountResolutionError::InvalidPubkey => {
                msg!("Failed to parse `Pubkey` from bytes")
            }
            AccountResolutionError::AccountTypeNotAccountMeta => {
                msg!(
                    "Attempted to deserialize an `AccountMeta` but the underlying type has PDA configs rather than a fixed address",
                )
            }
            AccountResolutionError::SeedConfigsTooLarge => {
                msg!("Provided list of seed configurations too large for a validation account",)
            }
            AccountResolutionError::NotEnoughBytesForSeed => {
                msg!("Not enough bytes available to pack seed configuration",)
            }
            AccountResolutionError::InvalidBytesForSeed => {
                msg!("The provided bytes are not valid for a seed configuration",)
            }
            AccountResolutionError::InvalidSeedConfig => {
                msg!("Tried to pack an invalid seed configuration",)
            }
            AccountResolutionError::InstructionDataTooSmall => {
                msg!("Instruction data too small for seed configuration",)
            }
            AccountResolutionError::AccountNotFound => {
                msg!("Could not find account at specified index",)
            }
            AccountResolutionError::CalculationFailure => {
                msg!("Error in checked math operation")
            }
            AccountResolutionError::AccountDataNotFound => {
                msg!("Could not find account data at specified index",)
            }
            AccountResolutionError::AccountDataTooSmall => {
                msg!("Account data too small for requested seed configuration",)
            }
            AccountResolutionError::AccountFetchFailed => {
                msg!("Failed to fetch account")
            }
            AccountResolutionError::NotEnoughBytesForPubkeyData => {
                msg!("Not enough bytes available to pack pubkey data configuration",)
            }
            AccountResolutionError::InvalidBytesForPubkeyData => {
                msg!("The provided bytes are not valid for a pubkey data configuration",)
            }
            AccountResolutionError::InvalidPubkeyDataConfig => {
                msg!("Tried to pack an invalid pubkey data configuration",)
            }
        }
    }
}