spl_binary_oracle_pair/
error.rs

1//! Error types
2
3use num_derive::FromPrimitive;
4use num_traits::FromPrimitive;
5use solana_program::{
6    decode_error::DecodeError, msg, program_error::PrintProgramError, program_error::ProgramError,
7};
8use thiserror::Error;
9
10/// Errors that may be returned by the Binary Oracle Pair program.
11#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)]
12pub enum PoolError {
13    /// Pool account already in use
14    #[error("Pool account already in use")]
15    AlreadyInUse,
16    /// Deposit account already in use
17    #[error("Deposit account already in use")]
18    DepositAccountInUse,
19    /// Token mint account already in use
20    #[error("Token account already in use")]
21    TokenMintInUse,
22    /// Invalid seed or bump_seed was provided
23    #[error("Failed to generate program account because of invalid data")]
24    InvalidAuthorityData,
25    /// Invalid authority account provided
26    #[error("Invalid authority account provided")]
27    InvalidAuthorityAccount,
28    /// Lamport balance below rent-exempt threshold.
29    #[error("Lamport balance below rent-exempt threshold")]
30    NotRentExempt,
31    /// Expected an SPL Token mint
32    #[error("Input token mint account is not valid")]
33    InvalidTokenMint,
34    /// Amount should be more than zero
35    #[error("Amount should be more than zero")]
36    InvalidAmount,
37    /// Wrong decider account
38    #[error("Wrong decider account was sent")]
39    WrongDeciderAccount,
40    /// Signature missing in transaction
41    #[error("Signature missing in transaction")]
42    SignatureMissing,
43    /// Decision was already made for this pool
44    #[error("Decision was already made for this pool")]
45    DecisionAlreadyMade,
46    /// Decision can't be made in current slot
47    #[error("Decision can't be made in current slot")]
48    InvalidSlotForDecision,
49    /// Deposit can't be made in current slot
50    #[error("Deposit can't be made in current slot")]
51    InvalidSlotForDeposit,
52    /// No decision has been made yet
53    #[error("No decision has been made yet")]
54    NoDecisionMadeYet,
55}
56
57impl From<PoolError> for ProgramError {
58    fn from(e: PoolError) -> Self {
59        ProgramError::Custom(e as u32)
60    }
61}
62
63impl<T> DecodeError<T> for PoolError {
64    fn type_of() -> &'static str {
65        "Binary Oracle Pair Error"
66    }
67}
68
69impl PrintProgramError for PoolError {
70    fn print<E>(&self)
71    where
72        E: 'static + std::error::Error + DecodeError<E> + PrintProgramError + FromPrimitive,
73    {
74        match self {
75            PoolError::AlreadyInUse => msg!("Error: Pool account already in use"),
76            PoolError::DepositAccountInUse => msg!("Error: Deposit account already in use"),
77            PoolError::TokenMintInUse => msg!("Error: Token account already in use"),
78            PoolError::InvalidAuthorityData => {
79                msg!("Error: Failed to generate program account because of invalid data")
80            }
81            PoolError::InvalidAuthorityAccount => msg!("Error: Invalid authority account provided"),
82            PoolError::NotRentExempt => msg!("Error: Lamport balance below rent-exempt threshold"),
83            PoolError::InvalidTokenMint => msg!("Error: Input token mint account is not valid"),
84            PoolError::InvalidAmount => msg!("Error: Amount should be more than zero"),
85            PoolError::WrongDeciderAccount => msg!("Error: Wrong decider account was sent"),
86            PoolError::SignatureMissing => msg!("Error: Signature missing in transaction"),
87            PoolError::DecisionAlreadyMade => {
88                msg!("Error: Decision was already made for this pool")
89            }
90            PoolError::InvalidSlotForDecision => {
91                msg!("Error: Decision can't be made in current slot")
92            }
93            PoolError::InvalidSlotForDeposit => msg!("Deposit can't be made in current slot"),
94            PoolError::NoDecisionMadeYet => msg!("Error: No decision has been made yet"),
95        }
96    }
97}