solana_message/versions/v1/
error.rs1use solana_sanitize::SanitizeError;
2
3#[derive(Debug, Clone, PartialEq, Eq)]
5#[non_exhaustive]
6pub enum MessageError {
7 BufferTooSmall,
9 InvalidHeapSize,
11 InstructionAccountsTooLarge,
13 InstructionDataTooLarge,
15 InvalidConfigMask,
17 InvalidInstructionAccountIndex,
19 InvalidProgramIdIndex,
21 InvalidVersion,
23 MissingLifetimeSpecifier,
25 NotEnoughAddressesForSignatures,
27 TooManyAddresses,
29 TooManyInstructions,
31 TooManySignatures,
33 TrailingData,
35 TransactionTooLarge,
37 ZeroSigners,
39 DuplicateAddresses,
41 InvalidConfigValue,
43 NotEnoughAccountKeys,
45}
46
47impl core::fmt::Display for MessageError {
48 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
49 match self {
50 Self::BufferTooSmall => write!(f, "buffer too small"),
51 Self::InvalidHeapSize => write!(f, "heap size must be a multiple of 1024"),
52 Self::InstructionAccountsTooLarge => {
53 write!(f, "instruction has too many accounts (max 255)")
54 }
55 Self::InstructionDataTooLarge => {
56 write!(f, "instruction data too large (max 65535 bytes)")
57 }
58 Self::InvalidConfigMask => write!(f, "invalid transaction config mask"),
59 Self::InvalidInstructionAccountIndex => {
60 write!(f, "instruction account index out of bounds")
61 }
62 Self::InvalidProgramIdIndex => {
63 write!(f, "program ID index out of bounds or is fee payer")
64 }
65 Self::InvalidVersion => write!(f, "invalid version byte (expected 0x81)"),
66 Self::MissingLifetimeSpecifier => {
67 write!(f, "lifetime specifier (blockhash) is required")
68 }
69 Self::NotEnoughAddressesForSignatures => {
70 write!(f, "not enough addresses for required signatures")
71 }
72 Self::TooManyAddresses => write!(f, "too many addresses (max 64)"),
73 Self::TooManyInstructions => write!(f, "too many instructions (max 64)"),
74 Self::TooManySignatures => write!(f, "too many signatures (max 12)"),
75 Self::TrailingData => write!(f, "unexpected trailing data"),
76 Self::TransactionTooLarge => write!(f, "transaction exceeds max size (4096 bytes)"),
77 Self::ZeroSigners => write!(f, "must have at least one signer (fee payer)"),
78 Self::DuplicateAddresses => write!(f, "duplicate addresses found in message"),
79 Self::InvalidConfigValue => write!(f, "invalid configuration value"),
80 Self::NotEnoughAccountKeys => write!(f, "not enough account keys provided"),
81 }
82 }
83}
84
85impl core::error::Error for MessageError {}
86
87impl From<MessageError> for SanitizeError {
88 fn from(err: MessageError) -> Self {
89 match err {
90 MessageError::BufferTooSmall
91 | MessageError::InvalidHeapSize
92 | MessageError::InstructionAccountsTooLarge
93 | MessageError::InstructionDataTooLarge
94 | MessageError::InvalidConfigMask
95 | MessageError::InvalidVersion
96 | MessageError::MissingLifetimeSpecifier
97 | MessageError::TrailingData
98 | MessageError::TransactionTooLarge
99 | MessageError::ZeroSigners
100 | MessageError::DuplicateAddresses
101 | MessageError::InvalidConfigValue
102 | MessageError::NotEnoughAccountKeys => SanitizeError::InvalidValue,
103 MessageError::InvalidInstructionAccountIndex
104 | MessageError::InvalidProgramIdIndex
105 | MessageError::NotEnoughAddressesForSignatures
106 | MessageError::TooManyAddresses
107 | MessageError::TooManyInstructions
108 | MessageError::TooManySignatures => SanitizeError::IndexOutOfBounds,
109 }
110 }
111}