module_ntoken/
error.rs

1//! Error types
2
3use num_derive::FromPrimitive;
4use num_traits::FromPrimitive;
5use solana_program::{decode_error::DecodeError, program_error::{ProgramError, PrintProgramError}, msg};
6use thiserror::Error;
7
8/// Errors that may be returned by the Token program.
9#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)]
10pub enum PortfolioError {
11    /// Lamport balance below rent-exempt threshold.
12    #[error("Lamport balance below rent-exempt threshold")]
13    NotRentExempt,
14    /// Insufficient funds for the operation requested.
15    #[error("Insufficient funds")]
16    InsufficientFunds,
17    /// Invalid Mint.
18    #[error("Invalid Mint")]
19    InvalidMint,
20    /// Account not associated with this Mint.
21    #[error("Account not associated with this Mint")]
22    MintMismatch,
23    /// Owner does not match.
24    #[error("Owner does not match")]
25    OwnerMismatch,
26    /// This token's supply is fixed and new tokens cannot be minted.
27    #[error("Fixed supply")]
28    FixedSupply,
29    /// The account cannot be initialized because it is already being used.
30    #[error("Already in use")]
31    AlreadyInUse,
32    /// Invalid number of provided signers.
33    #[error("Invalid number of provided signers")]
34    InvalidNumberOfProvidedSigners,
35    /// Invalid number of required signers.
36    #[error("Invalid number of required signers")]
37    InvalidNumberOfRequiredSigners,
38    /// State is uninitialized.
39    #[error("State is unititialized")]
40    UninitializedState,
41    /// Instruction does not support native tokens
42    #[error("Instruction does not support native tokens")]
43    NativeNotSupported,
44    /// Non-native account can only be closed if its balance is zero
45    #[error("Non-native account can only be closed if its balance is zero")]
46    NonNativeHasBalance,
47    /// Invalid instruction
48    #[error("Invalid instruction")]
49    InvalidInstruction,
50    /// State is invalid for requested operation.
51    #[error("State is invalid for requested operation")]
52    InvalidState,
53    /// Operation overflowed
54    #[error("Operation overflowed")]
55    Overflow,
56    /// Account does not support specified authority type.
57    #[error("Account does not support specified authority type")]
58    AuthorityTypeNotSupported,
59    /// This token mint cannot freeze accounts.
60    #[error("This token mint cannot freeze accounts")]
61    MintCannotFreeze,
62    /// Account is frozen; all account operations will fail
63    #[error("Account is frozen")]
64    AccountFrozen,
65    /// Mint decimals mismatch between the client and mint
66    #[error("The provided decimals value different from the Mint decimals")]
67    MintDecimalsMismatch,
68    /// Invalid amount, must be greater then zero
69    #[error("Input amount is invalid")]
70    InvalidAmount,
71    /// Invalid type of account
72    #[error("Invalid type account")]
73    InvalidTypeAccount,
74    /// Error while create user portfolio
75    #[error("Error while create user portfolio")]
76    ErrorWhileCreatePPU,
77    /// Maximum number of splu attended
78    #[error("Exceeded numbre of splu")]
79    MaximumSPLUAdded,
80    /// Maximum number of admins attended
81    #[error("Exceeded numbre of admins")]
82    MaximumADMINAdded,
83    /// Missing admin authorization
84    #[error("Missing admin authorization")]
85    MissingAdminAuthorization,
86    /// Error while adding new asset to portfolio
87    #[error("Error while adding new asset to portfolio")]
88    ErrorWhileAddingNewAssetToPortfolio,
89    /// Error while adding new splu to user portfolio
90    #[error("Error while adding new splu to user portfolio")]
91    ErrorWhileAddingNewSpluToUserPortfolio,
92    /// Error while adding new ppu to distribute account
93    #[error("Maximum number of ppu was attended")]
94    MaximumNumberOfPPUWasAttended,
95    /// Error invalid state of user portfolio account
96    #[error("Error invalid state of user portfolio account")]
97    InvalidStateOfPPU,
98    /// Error invalid state of portfolio account
99    #[error("Error invalid state of portfolio account")]
100    InvalidStateOfPPM,
101    /// Error while updating data account
102    #[error("Error while updating data account")]
103    ErrorWhileUpdatingDataAccount,
104    /// Error while executing external transaction
105    #[error("Error while executing an external transaction")]
106    ErrorFromExternalTransaction,
107    
108}
109impl From<PortfolioError> for ProgramError {
110    fn from(e: PortfolioError) -> Self {
111        ProgramError::Custom(e as u32)
112    }
113}
114impl<T> DecodeError<T> for PortfolioError {
115    fn type_of() -> &'static str {
116        "PortfolioError"
117    }
118}
119
120
121
122impl PrintProgramError for PortfolioError {
123    fn print<E>(&self)
124    where
125        E: 'static + std::error::Error + DecodeError<E> + PrintProgramError + FromPrimitive,
126    {
127        match self {
128            PortfolioError::NotRentExempt => {
129                msg!("Error: Lamport balance below rent-exempt threshold")
130            }
131            PortfolioError::InsufficientFunds => msg!("Error: insufficient funds"),
132            PortfolioError::InvalidMint => msg!("Error: Invalid Mint"),
133            PortfolioError::MintMismatch => msg!("Error: Account not associated with this Mint"),
134            PortfolioError::OwnerMismatch => msg!("Error: owner does not match"),
135            PortfolioError::FixedSupply => msg!("Error: the total supply of this token is fixed"),
136            PortfolioError::AlreadyInUse => msg!("Error: account or token already in use"),
137            PortfolioError::InvalidNumberOfProvidedSigners => {
138                msg!("Error: Invalid number of provided signers")
139            }
140            PortfolioError::InvalidNumberOfRequiredSigners => {
141                msg!("Error: Invalid number of required signers")
142            }
143            PortfolioError::UninitializedState => msg!("Error: State is uninitialized"),
144            PortfolioError::NativeNotSupported => {
145                msg!("Error: Instruction does not support native tokens")
146            }
147            PortfolioError::NonNativeHasBalance => {
148                msg!("Error: Non-native account can only be closed if its balance is zero")
149            }
150            PortfolioError::InvalidInstruction => msg!("Error: Invalid instruction"),
151            PortfolioError::InvalidState => msg!("Error: Invalid account state for operation"),
152            PortfolioError::Overflow => msg!("Error: Operation overflowed"),
153            PortfolioError::AuthorityTypeNotSupported => {
154                msg!("Error: Account does not support specified authority type")
155            }
156            PortfolioError::MintCannotFreeze => {
157                msg!("Error: This token mint cannot freeze accounts")
158            }
159            PortfolioError::AccountFrozen => msg!("Error: Account is frozen"),
160            PortfolioError::MintDecimalsMismatch => {
161                msg!("Error: decimals different from the Mint decimals")
162            }
163            PortfolioError::InvalidAmount => {
164                msg!("Error: invalid amount ")
165            }
166            PortfolioError::InvalidTypeAccount => {
167                msg!("Error: Invalid type account ")
168            }
169            PortfolioError::ErrorWhileCreatePPU => {
170                msg!("Error: Error while create user portfolio ")
171            }
172
173            PortfolioError::MaximumSPLUAdded => {
174                msg!("Error: Maximum number of splu attended ")
175            }
176            PortfolioError::MaximumADMINAdded => {
177                msg!("Error: Maximum number of admins attended ")
178            }
179            PortfolioError::MissingAdminAuthorization => {
180                msg!("Error: Missing admin authorization ")
181            }
182            PortfolioError::ErrorWhileAddingNewAssetToPortfolio => {
183                msg!("Error: Error while adding new asset to portfolio ")
184            }
185            PortfolioError::ErrorWhileAddingNewSpluToUserPortfolio => {
186                msg!("Error: Error while adding new splu to user portfolio ")
187            }
188            PortfolioError::MaximumNumberOfPPUWasAttended => {
189                msg!("Error: Maximum number of ppu was attended ")
190            }
191            PortfolioError:: InvalidStateOfPPU => {
192                msg!("Error invalid state of user portfolio account")
193            }
194            PortfolioError:: InvalidStateOfPPM => {
195                msg!("Error invalid state of portfolio account")
196            }
197            PortfolioError:: ErrorWhileUpdatingDataAccount => {
198                msg!("Error Error while updating data account")
199            }
200            PortfolioError:: ErrorFromExternalTransaction => {
201                msg!("Error while executing an external transaction")
202            }
203             
204        }
205    }
206}