Rename CustomError to Custom (#9207)

This commit is contained in:
Jack May
2020-04-01 09:01:11 -07:00
committed by GitHub
parent 7605f1f540
commit 268e04cb4a
19 changed files with 59 additions and 79 deletions

View File

@ -15,7 +15,7 @@ pub enum ProgramError {
/// by the Solana runtime. A program-specific error may be any type that is represented as
/// or serialized to a u32 integer.
#[error("Custom program error: {0}")]
CustomError(u32),
Custom(u32),
#[error("The arguments provided to a program instruction where invalid")]
InvalidArgument,
#[error("An instruction's data contents was invalid")]
@ -52,7 +52,7 @@ impl PrintProgramError for ProgramError {
E: 'static + std::error::Error + DecodeError<E> + PrintProgramError + FromPrimitive,
{
match self {
ProgramError::CustomError(error) => {
ProgramError::Custom(error) => {
if let Some(custom_error) = E::decode_custom_error_to_enum(*error) {
custom_error.print::<E>();
} else {
@ -109,7 +109,7 @@ impl From<ProgramError> for u64 {
ProgramError::UninitializedAccount => UNINITIALIZED_ACCOUNT,
ProgramError::NotEnoughAccountKeys => NOT_ENOUGH_ACCOUNT_KEYS,
ProgramError::AccountBorrowFailed => ACCOUNT_BORROW_FAILED,
ProgramError::CustomError(error) => {
ProgramError::Custom(error) => {
if error == 0 {
CUSTOM_ZERO
} else {
@ -134,8 +134,8 @@ impl From<u64> for ProgramError {
UNINITIALIZED_ACCOUNT => ProgramError::UninitializedAccount,
NOT_ENOUGH_ACCOUNT_KEYS => ProgramError::NotEnoughAccountKeys,
ACCOUNT_BORROW_FAILED => ProgramError::AccountBorrowFailed,
CUSTOM_ZERO => ProgramError::CustomError(0),
_ => ProgramError::CustomError(error as u32),
CUSTOM_ZERO => ProgramError::Custom(0),
_ => ProgramError::Custom(error as u32),
}
}
}
@ -145,7 +145,7 @@ impl TryFrom<InstructionError> for ProgramError {
fn try_from(error: InstructionError) -> Result<Self, Self::Error> {
match error {
Self::Error::CustomError(err) => Ok(Self::CustomError(err)),
Self::Error::Custom(err) => Ok(Self::Custom(err)),
Self::Error::InvalidArgument => Ok(Self::InvalidArgument),
Self::Error::InvalidInstructionData => Ok(Self::InvalidInstructionData),
Self::Error::InvalidAccountData => Ok(Self::InvalidAccountData),
@ -169,7 +169,7 @@ where
fn from(error: T) -> Self {
let error = error.to_u64().unwrap_or(0xbad_c0de);
match error {
CUSTOM_ZERO => InstructionError::CustomError(0),
CUSTOM_ZERO => InstructionError::Custom(0),
INVALID_ARGUMENT => InstructionError::InvalidArgument,
INVALID_INSTRUCTION_DATA => InstructionError::InvalidInstructionData,
INVALID_ACCOUNT_DATA => InstructionError::InvalidAccountData,
@ -184,7 +184,7 @@ where
_ => {
// A valid custom error has no bits set in the upper 32
if error >> BUILTIN_BIT_SHIFT == 0 {
InstructionError::CustomError(error as u32)
InstructionError::Custom(error as u32)
} else {
InstructionError::InvalidError
}