spl_account_compression/
error.rs1use anchor_lang::{
2 prelude::*,
3 solana_program::{msg, program_error::ProgramError},
4};
5use bytemuck::PodCastError;
6use spl_concurrent_merkle_tree::error::ConcurrentMerkleTreeError;
7use std::any::type_name;
8use std::mem::size_of;
9
10#[error_code]
12pub enum AccountCompressionError {
13 #[msg("Incorrect leaf length. Expected vec of 32 bytes")]
15 IncorrectLeafLength,
16
17 #[msg("Concurrent merkle tree error")]
20 ConcurrentMerkleTreeError,
21
22 #[msg("Issue zero copying concurrent merkle tree data")]
24 ZeroCopyError,
25
26 #[msg("An unsupported max depth or max buffer size constant was provided")]
28 ConcurrentMerkleTreeConstantsError,
29
30 #[msg("Expected a different byte length for the merkle tree canopy")]
32 CanopyLengthMismatch,
33
34 #[msg("Provided authority does not match expected tree authority")]
36 IncorrectAuthority,
37
38 #[msg("Account is owned by a different program, expected it to be owned by this program")]
40 IncorrectAccountOwner,
41
42 #[msg("Account provided has incorrect account type")]
44 IncorrectAccountType,
45
46 #[msg("Leaf index of concurrent merkle tree is out of bounds")]
49 LeafIndexOutOfBounds,
50}
51
52impl From<&ConcurrentMerkleTreeError> for AccountCompressionError {
53 fn from(_error: &ConcurrentMerkleTreeError) -> Self {
54 AccountCompressionError::ConcurrentMerkleTreeError
55 }
56}
57
58pub fn error_msg<T>(data_len: usize) -> impl Fn(PodCastError) -> ProgramError {
59 move |_: PodCastError| -> ProgramError {
60 msg!(
61 "Failed to load {}. Size is {}, expected {}",
62 type_name::<T>(),
63 data_len,
64 size_of::<T>(),
65 );
66 ProgramError::InvalidAccountData
67 }
68}