diff --git a/runtime/src/runtime.rs b/runtime/src/runtime.rs index e8b3f7bb35..3bf2254c37 100644 --- a/runtime/src/runtime.rs +++ b/runtime/src/runtime.rs @@ -107,7 +107,14 @@ fn execute_instruction( executable_accounts, program_accounts, tick_height, - )?; + ) + .map_err(|err| match err { + ProgramError::CustomError(mut error) => { + error.truncate(32); + ProgramError::CustomError(error) + } + e => e, + })?; // Verify the instruction for ((pre_program_id, pre_lamports, pre_userdata), post_account) in diff --git a/sdk/src/native_program.rs b/sdk/src/native_program.rs index e2bf0965fc..6c9e8e548d 100644 --- a/sdk/src/native_program.rs +++ b/sdk/src/native_program.rs @@ -36,6 +36,12 @@ pub enum ProgramError { /// SystemInstruction::Assign was attempted on an account unowned by the system program AssignOfUnownedAccount, + + /// CustomError allows on-chain programs to implement program-specific error types and see + /// them returned by the Solana runtime. A CustomError may be any type that is serialized + /// to a Vec of bytes, max length 32 bytes. Any CustomError Vec greater than this length will + /// be truncated by the runtime. + CustomError(Vec), } impl std::fmt::Display for ProgramError {