Trait solana_program::decode_error::DecodeError
source · pub trait DecodeError<E> {
// Required method
fn type_of() -> &'static str;
// Provided method
fn decode_custom_error_to_enum(custom: u32) -> Option<E>
where E: FromPrimitive { ... }
}
Expand description
Allows custom errors to be decoded back to their original enum.
Some Safecoin error enums, like ProgramError
, include a Custom
variant,
like ProgramError::Custom
, that contains a u32
error code. This code
may represent any error that is not covered by the error enum’s named
variants. It is common for programs to convert their own error enums to an
error code and store it in the Custom
variant, possibly with the help of
the ToPrimitive
trait.
This trait builds on the FromPrimitive
trait to help convert those error
codes to the original error enum they represent.
As this allows freely converting u32
to any type that implements
FromPrimitive
, it is only used correctly when the caller is certain of the
original error type.