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 #[msg("Tree was initialized without allocating space for the canopy")]
53 CanopyNotAllocated,
54
55 #[msg("Tree was already initialized")]
57 TreeAlreadyInitialized,
58
59 #[msg("Tree header was not initialized for batch processing")]
61 BatchNotInitialized,
62
63 #[msg("Canopy root does not match the root of the tree")]
65 CanopyRootMismatch,
66
67 #[msg("Canopy contains nodes to the right of the rightmost leaf of the tree")]
69 CanopyRightmostLeafMismatch,
70}
71
72impl From<&ConcurrentMerkleTreeError> for AccountCompressionError {
73 fn from(_error: &ConcurrentMerkleTreeError) -> Self {
74 AccountCompressionError::ConcurrentMerkleTreeError
75 }
76}
77
78pub fn error_msg<T>(data_len: usize) -> impl Fn(PodCastError) -> ProgramError {
79 move |_: PodCastError| -> ProgramError {
80 msg!(
81 "Failed to load {}. Size is {}, expected {}",
82 type_name::<T>(),
83 data_len,
84 size_of::<T>(),
85 );
86 ProgramError::InvalidAccountData
87 }
88}