-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
Problem
Currently the methods generated by the below two macros return the same error no matter which part of the deserialization fails, discriminator check, bytemuck deserialization, etc.
impl_to_bytes_with_discriminator_zero_copy!(DelegationRecord);
impl_try_from_bytes_with_discriminator_zero_copy!(DelegationRecord);
Here is a snippet:
pub fn try_from_bytes_with_discriminator(
data: &[u8],
) -> Result<&Self, ::solana_program::program_error::ProgramError> {
if data.len() < 8 {
return Err(::solana_program::program_error::ProgramError::InvalidAccountData);
}
if Self::discriminator().to_bytes().ne(&data[..8]) {
return Err(::solana_program::program_error::ProgramError::InvalidAccountData);
}
bytemuck::try_from_bytes::<Self>(&data[8..]).or(Err(
::solana_program::program_error::ProgramError::InvalidAccountData,
))
}This makes it really hard to know which part of this failed.
Solution
Construct a more meaningful error if possible and/or include more information with a common error.
Metadata
Metadata
Assignees
Labels
No labels