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 InstructionAccountsTooLarge,
11 InstructionDataTooLarge,
13 InvalidConfigMask,
15 InvalidInstructionAccountIndex,
17 InvalidProgramIdIndex,
19 InvalidVersion,
21 MissingLifetimeSpecifier,
23 NotEnoughAddressesForSignatures,
25 TooManyAddresses,
27 TooManyInstructions,
29 TrailingData,
31 TransactionTooLarge,
33 ZeroSigners,
35 InvalidConfigValue,
37 NotEnoughAccountKeys,
39}
40
41impl core::fmt::Display for MessageError {
42 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
43 match self {
44 Self::BufferTooSmall => write!(f, "buffer too small"),
45 Self::InstructionAccountsTooLarge => {
46 write!(f, "instruction has too many accounts (max 255)")
47 }
48 Self::InstructionDataTooLarge => {
49 write!(f, "instruction data too large (max 65535 bytes)")
50 }
51 Self::InvalidConfigMask => write!(f, "invalid transaction config mask"),
52 Self::InvalidInstructionAccountIndex => {
53 write!(f, "instruction account index out of bounds")
54 }
55 Self::InvalidProgramIdIndex => {
56 write!(f, "program ID index out of bounds or is fee payer")
57 }
58 Self::InvalidVersion => write!(f, "invalid version byte (expected 0x81)"),
59 Self::MissingLifetimeSpecifier => {
60 write!(f, "lifetime specifier (blockhash) is required")
61 }
62 Self::NotEnoughAddressesForSignatures => {
63 write!(f, "not enough addresses for required signatures")
64 }
65 Self::TooManyAddresses => write!(f, "too many addresses (max 255)"),
66 Self::TooManyInstructions => write!(f, "too many instructions (max 255)"),
67 Self::TrailingData => write!(f, "unexpected trailing data"),
68 Self::TransactionTooLarge => write!(f, "transaction exceeds max size (4096 bytes)"),
69 Self::ZeroSigners => write!(f, "must have at least one signer (fee payer)"),
70 Self::InvalidConfigValue => write!(f, "invalid configuration value"),
71 Self::NotEnoughAccountKeys => write!(f, "not enough account keys provided"),
72 }
73 }
74}
75
76impl core::error::Error for MessageError {}
77
78impl From<MessageError> for SanitizeError {
79 fn from(err: MessageError) -> Self {
80 match err {
81 MessageError::BufferTooSmall
82 | MessageError::InstructionAccountsTooLarge
83 | MessageError::InstructionDataTooLarge
84 | MessageError::InvalidConfigMask
85 | MessageError::InvalidVersion
86 | MessageError::MissingLifetimeSpecifier
87 | MessageError::TrailingData
88 | MessageError::TransactionTooLarge
89 | MessageError::ZeroSigners
90 | MessageError::InvalidConfigValue
91 | MessageError::NotEnoughAccountKeys => SanitizeError::InvalidValue,
92 MessageError::InvalidInstructionAccountIndex
93 | MessageError::InvalidProgramIdIndex
94 | MessageError::NotEnoughAddressesForSignatures
95 | MessageError::TooManyAddresses
96 | MessageError::TooManyInstructions => SanitizeError::IndexOutOfBounds,
97 }
98 }
99}