ntoken_solana_models/
error.rs

1//! Error types
2
3use num_derive::FromPrimitive;
4use num_traits::FromPrimitive;
5use solana_program::{
6    decode_error::DecodeError,
7    msg,
8    program_error::{PrintProgramError, ProgramError},
9};
10use thiserror::Error;
11
12/// Errors that may be returned by the Token program.
13#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)]
14pub enum PortfolioError {
15    /// Lamport balance below rent-exempt threshold.
16    #[error("Lamport balance below rent-exempt threshold")]
17    NotRentExempt,
18    /// Owner does not match.
19    #[error("Owner does not match")]
20    OwnerMismatch,
21    /// The account cannot be initialized because it is already being used.
22    #[error("Already in use")]
23    AlreadyInUse,
24    /// State is uninitialized.
25    #[error("State is unititialized")]
26    UninitializedState,
27    /// Invalid instruction
28    #[error("Invalid instruction")]
29    InvalidInstruction,
30    /// State is invalid for requested operation.
31    #[error("State is invalid for requested operation")]
32    InvalidState,
33    /// Operation overflowed
34    #[error("Operation overflowed")]
35    Overflow,
36    /// Invalid amount, must be greater then zero
37    #[error("Input amount is invalid")]
38    InvalidAmount,
39    /// Invalid type of account
40    #[error("Invalid type account")]
41    InvalidTypeAccount,
42    /// Error while create user portfolio
43    #[error("Error while create user portfolio")]
44    ErrorWhileCreatePPU,
45    /// Maximum number of splu attended
46    #[error("Exceeded numbre of splu")]
47    MaximumSPLUAdded,
48    /// Maximum number of admins attended
49    #[error("Exceeded numbre of admins")]
50    MaximumADMINAdded,
51    /// Missing admin authorization
52    #[error("Missing admin authorization")]
53    MissingAdminAuthorization,
54    /// Error while adding new asset to portfolio
55    #[error("Error while adding new asset to portfolio")]
56    ErrorWhileAddingNewAssetToPortfolio,
57    /// Error while adding new splu to user portfolio
58    #[error("Error while adding new splu to user portfolio")]
59    ErrorWhileAddingNewSpluToUserPortfolio,
60    /// Error while adding new ppu to distribute account
61    #[error("Maximum number of ppu was attended")]
62    MaximumNumberOfUserWasAttended,
63    /// Error invalid state of user account
64    #[error("Error invalid state of user account")]
65    InvalidStateOfPPU,
66    /// Error invalid state of turing machine account
67    #[error("Error invalid state of turing machine account")]
68    InvalidStateOfTuringMachine,
69    /// Error invalid state of portfolio account
70    #[error("Error invalid state of portfolio account")]
71    InvalidStateOfPPM,
72    /// Error while updating data account
73    #[error("Error while updating data account")]
74    ErrorWhileUpdatingDataAccount,
75    /// Error while executing external transaction
76    #[error("Error while executing an external transaction")]
77    ErrorFromExternalTransaction,
78    /// Error invalid mint
79    #[error("Error invalid mint")]
80    ErrorInvalidMint,
81    /// Error while adding splu secondary temporal to turing machine
82    #[error("Error while adding splu secondary temporal to turing machine")]
83    ErrorWhileAddingSpluSecTmpToTuringMachine,
84    /// Error invalid time
85    #[error("Error invalid time")]
86    InvalidTime,
87    /// Maximum number of splm assets attended
88    #[error("Exceeded numbre of splm assets")]
89    MaximumSplmAssetsAdded,
90    /// splm asset not registred
91    #[error("splm asset not registred")]
92    SplmAssetNotRegistred,
93    
94}
95impl From<PortfolioError> for ProgramError {
96    fn from(e: PortfolioError) -> Self {
97        ProgramError::Custom(e as u32)
98    }
99}
100impl<T> DecodeError<T> for PortfolioError {
101    fn type_of() -> &'static str {
102        "PortfolioError"
103    }
104}
105
106impl PrintProgramError for PortfolioError {
107    fn print<E>(&self)
108    where
109        E: 'static + std::error::Error + DecodeError<E> + PrintProgramError + FromPrimitive,
110    {
111        match self {
112            PortfolioError::NotRentExempt => {
113                msg!("Error: Lamport balance below rent-exempt threshold")
114            }
115            PortfolioError::OwnerMismatch => msg!("Error: owner does not match"),
116            PortfolioError::AlreadyInUse => msg!("Error: account or token already in use"),
117            PortfolioError::UninitializedState => msg!("Error: State is uninitialized"),
118            PortfolioError::InvalidInstruction => msg!("Error: Invalid instruction"),
119            PortfolioError::InvalidState => msg!("Error: Invalid account state for operation"),
120            PortfolioError::Overflow => msg!("Error: Operation overflowed"),
121            PortfolioError::InvalidAmount => {
122                msg!("Error: invalid amount ")
123            }
124            PortfolioError::InvalidTypeAccount => {
125                msg!("Error: Invalid type account ")
126            }
127            PortfolioError::ErrorWhileCreatePPU => {
128                msg!("Error: Error while create user portfolio ")
129            }
130
131            PortfolioError::MaximumSPLUAdded => {
132                msg!("Error: Maximum number of splu attended ")
133            }
134            PortfolioError::MaximumADMINAdded => {
135                msg!("Error: Maximum number of admins attended ")
136            }
137            PortfolioError::MissingAdminAuthorization => {
138                msg!("Error: Missing admin authorization ")
139            }
140            PortfolioError::ErrorWhileAddingNewAssetToPortfolio => {
141                msg!("Error: Error while adding new asset to portfolio ")
142            }
143            PortfolioError::ErrorWhileAddingNewSpluToUserPortfolio => {
144                msg!("Error: Error while adding new splu to user portfolio ")
145            }
146            PortfolioError::MaximumNumberOfUserWasAttended => {
147                msg!("Error: Maximum number of user was attended ")
148            }
149            PortfolioError::InvalidStateOfPPU => {
150                msg!("Error invalid state of user portfolio account")
151            }
152            PortfolioError::InvalidStateOfTuringMachine => {
153                msg!("Error invalid state of turing machine account")
154            }
155            PortfolioError::InvalidStateOfPPM => {
156                msg!("Error invalid state of portfolio account")
157            }
158            PortfolioError::ErrorWhileUpdatingDataAccount => {
159                msg!("Error Error while updating data account")
160            }
161            PortfolioError::ErrorFromExternalTransaction => {
162                msg!("Error while executing an external transaction")
163            }
164            PortfolioError::ErrorInvalidMint => {
165                msg!("Error invalid mint")
166            }
167            PortfolioError::ErrorWhileAddingSpluSecTmpToTuringMachine => {
168                msg!("Error while adding splu secondary temporal to turing machine")
169            }
170            PortfolioError::InvalidTime => {
171                msg!("Error invalid time")
172            }
173            PortfolioError::MaximumSplmAssetsAdded => {
174                msg!("Error: Maximum number of splm assets attended ")
175            }
176            PortfolioError::SplmAssetNotRegistred => {
177                msg!("Error: Splm asset not registred")
178            }
179        }
180    }
181}