Add support for idiomatic error handling to BPF instruction processors (#7968)
This commit is contained in:
@ -15,7 +15,6 @@ use solana_sdk::{
|
||||
sysvar::rent,
|
||||
};
|
||||
use std::{
|
||||
convert::TryFrom,
|
||||
io::{prelude::*, Error},
|
||||
mem,
|
||||
};
|
||||
@ -145,18 +144,15 @@ pub fn process_instruction(
|
||||
|
||||
info!("Call BPF program");
|
||||
match vm.execute_program(parameter_bytes.as_slice(), &[], &[heap_region]) {
|
||||
Ok(status) => match u32::try_from(status) {
|
||||
Ok(status) => {
|
||||
if status > 0 {
|
||||
warn!("BPF program failed: {}", status);
|
||||
return Err(InstructionError::CustomError(status));
|
||||
}
|
||||
Ok(status) => {
|
||||
// ignore upper 32bits if any, programs only return lower 32bits
|
||||
let status = status as u32;
|
||||
if status != 0 {
|
||||
let error: InstructionError = status.into();
|
||||
warn!("BPF program failed: {:?}", error);
|
||||
return Err(error);
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("BPF VM encountered invalid status: {}", e);
|
||||
return Err(InstructionError::GenericError);
|
||||
}
|
||||
},
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("BPF VM failed to run program: {}", e);
|
||||
return Err(InstructionError::GenericError);
|
||||
|
Reference in New Issue
Block a user