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