use num_derive::FromPrimitive;
use solana_program::{
decode_error::DecodeError,
msg,
program_error::{PrintProgramError, ProgramError},
};
use thiserror::Error;
#[derive(Error, Clone, Debug, Eq, PartialEq, FromPrimitive)]
pub enum RuleSetError {
#[error("Numerical Overflow")]
NumericalOverflow,
#[error("Data type mismatch")]
DataTypeMismatch,
#[error("Data slice unexpected index error")]
DataSliceUnexpectedIndexError,
#[error("Incorrect account owner")]
IncorrectOwner,
#[error("Could not index into PayloadVec")]
PayloadVecIndexError,
#[error("Derived key invalid")]
DerivedKeyInvalid,
#[error("Payer is not a signer")]
PayerIsNotSigner,
#[error("Not implemented")]
NotImplemented,
#[error("Borsh serialization error")]
BorshSerializationError,
#[error("Borsh deserialization error")]
BorshDeserializationError,
#[error("Value in Payload or RuleSet is occupied")]
ValueOccupied,
#[error("Account data is empty")]
DataIsEmpty,
#[error("MessagePack serialization error")]
MessagePackSerializationError,
#[error("MessagePack deserialization error")]
MessagePackDeserializationError,
#[error("Missing account")]
MissingAccount,
#[error("Missing Payload value")]
MissingPayloadValue,
#[error("RuleSet owner must be payer")]
RuleSetOwnerMismatch,
#[error("Name too long")]
NameTooLong,
#[error("The operation retrieved is not in the selected RuleSet")]
OperationNotFound,
#[error("Rule authority is not signer")]
RuleAuthorityIsNotSigner,
#[error("Unsupported RuleSet revision map version")]
UnsupportedRuleSetRevMapVersion,
#[error("Unsupported RuleSet version")]
UnsupportedRuleSetVersion,
#[error("Unexpected RuleSet failure")]
UnexpectedRuleSetFailure,
#[error("RuleSet revision not available")]
RuleSetRevisionNotAvailable,
#[error("Additional Signer check failed")]
AdditionalSignerCheckFailed,
#[error("Pubkey Match check failed")]
PubkeyMatchCheckFailed,
#[error("Pubkey List Match check failed")]
PubkeyListMatchCheckFailed,
#[error("Pubkey Tree Match check failed")]
PubkeyTreeMatchCheckFailed,
#[error("PDA Match check failed")]
PDAMatchCheckFailed,
#[error("Program Owned check failed")]
ProgramOwnedCheckFailed,
#[error("Program Owned List check failed")]
ProgramOwnedListCheckFailed,
#[error("Program Owned Tree check failed")]
ProgramOwnedTreeCheckFailed,
#[error("Amount checked failed")]
AmountCheckFailed,
#[error("Frequency check failed")]
FrequencyCheckFailed,
#[error("IsWallet check failed")]
IsWalletCheckFailed,
#[error("Program Owned Set check failed")]
ProgramOwnedSetCheckFailed,
#[error("Invalid compare operator")]
InvalidCompareOp,
#[error("Invalid constraint type value")]
InvalidConstraintType,
#[error("Failed to read the rule set")]
RuleSetReadFailed,
#[error("Duplicated operation name")]
DuplicatedOperationName,
#[error("Could not determine alignemnt")]
AlignmentError,
}
impl PrintProgramError for RuleSetError {
fn print<E>(&self) {
msg!(&self.to_string());
}
}
impl From<RuleSetError> for ProgramError {
fn from(e: RuleSetError) -> Self {
ProgramError::Custom(e as u32)
}
}
impl<T> DecodeError<T> for RuleSetError {
fn type_of() -> &'static str {
"Error Thingy"
}
}