Remove program error footgun and cleaner developer experience (#8042)

This commit is contained in:
Jack May
2020-01-31 10:58:07 -08:00
committed by GitHub
parent eff876881b
commit 0fd795a676
26 changed files with 127 additions and 160 deletions

View File

@@ -4,7 +4,7 @@ extern crate solana_sdk;
use solana_sdk::entrypoint::SUCCESS;
#[no_mangle]
pub extern "C" fn entrypoint(_input: *mut u8) -> u32 {
pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
let x: u128 = 1;
let y = x.rotate_right(1);
assert_eq!(y, 170_141_183_460_469_231_731_687_303_715_884_105_728);

View File

@@ -7,7 +7,7 @@ use solana_sdk::{entrypoint::SUCCESS, info};
use std::{alloc::Layout, mem};
#[no_mangle]
pub extern "C" fn entrypoint(_input: *mut u8) -> u32 {
pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
unsafe {
// Confirm large allocation fails

View File

@@ -5,7 +5,7 @@ use byteorder::{ByteOrder, LittleEndian};
use solana_sdk::entrypoint::SUCCESS;
#[no_mangle]
pub extern "C" fn entrypoint(_input: *mut u8) -> u32 {
pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
let mut buf = [0; 4];
LittleEndian::write_u32(&mut buf, 1_000_000);
assert_eq!(1_000_000, LittleEndian::read_u32(&buf));

View File

@@ -9,15 +9,11 @@ use thiserror::Error;
/// Custom program errors
#[derive(Error, Debug, Clone, PartialEq, FromPrimitive)]
// Clippy compains about 0x8000_002d, but we don't care about C compatibility here
#[allow(clippy::enum_clike_unportable_variant)]
pub enum MyError {
#[error("Default enum start")]
DefaultEnumStart,
#[error("The Answer")]
TheAnswer = 42,
#[error("Conflicting with success")]
ConflictingSuccess = 0,
#[error("Conflicting with builtin")]
ConflictingBuiltin = 0x8000_002d,
}
impl From<MyError> for ProgramError {
fn from(e: MyError) -> Self {
@@ -41,16 +37,12 @@ fn process_instruction(
Err(ProgramError::InvalidAccountData)
}
3 => {
info!("return custom error");
Err(MyError::TheAnswer.into())
info!("return default enum start value");
Err(MyError::DefaultEnumStart.into())
}
4 => {
info!("return error that conflicts with success");
Err(MyError::ConflictingSuccess.into())
}
5 => {
info!("return error that conflicts with builtin");
Err(MyError::ConflictingBuiltin.into())
info!("return custom error");
Err(MyError::TheAnswer.into())
}
6 => {
let data = accounts[0].try_borrow_mut_data()?;

View File

@@ -4,7 +4,7 @@ extern crate solana_sdk;
use solana_sdk::{entrypoint::SUCCESS, info};
#[no_mangle]
pub extern "C" fn entrypoint(_input: *mut u8) -> u32 {
pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
const ITERS: usize = 100;
let ones = [1_u64; ITERS];
let mut sum: u64 = 0;

View File

@@ -5,7 +5,7 @@ extern crate solana_sdk;
use solana_sdk::{entrypoint::SUCCESS, info};
#[no_mangle]
pub extern "C" fn entrypoint(_input: *mut u8) -> u32 {
pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
info!("Call same package");
assert_eq!(crate::helper::many_args(1, 2, 3, 4, 5, 6, 7, 8, 9), 45);

View File

@@ -3,6 +3,6 @@
extern crate solana_sdk;
#[no_mangle]
pub extern "C" fn entrypoint(_input: *mut u8) -> u32 {
pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
panic!();
}

View File

@@ -5,7 +5,7 @@ use solana_bpf_rust_param_passing_dep::{Data, TestDep};
use solana_sdk::{entrypoint::SUCCESS, info};
#[no_mangle]
pub extern "C" fn entrypoint(_input: *mut u8) -> u32 {
pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
let array = [0xA, 0xB, 0xC, 0xD, 0xE, 0xF];
let data = Data {
twentyone: 21u64,