error.rs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //! Error types
  2. use num_derive::FromPrimitive;
  3. use solana_sdk::{decode_error::DecodeError, program_error::ProgramError};
  4. use thiserror::Error;
  5. /// Errors that may be returned by the Token program.
  6. #[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)]
  7. pub enum TokenError {
  8. /// Lamport balance below rent-exempt threshold.
  9. #[error("Lamport balance below rent-exempt threshold")]
  10. NotRentExempt,
  11. /// Insufficient funds for the operation requested.
  12. #[error("Insufficient funds")]
  13. InsufficientFunds,
  14. /// Invalid Mint.
  15. #[error("Invalid Mint")]
  16. InvalidMint,
  17. /// Account not associated with this Mint.
  18. #[error("Account not associated with this Mint")]
  19. MintMismatch,
  20. /// Owner does not match.
  21. #[error("Owner does not match")]
  22. OwnerMismatch,
  23. /// This token's supply is fixed and new tokens cannot be minted.
  24. #[error("Fixed supply")]
  25. FixedSupply,
  26. /// The account cannot be initialized because it is already being used.
  27. #[error("Already in use")]
  28. AlreadyInUse,
  29. /// Invalid number of provided signers.
  30. #[error("Invalid number of provided signers")]
  31. InvalidNumberOfProvidedSigners,
  32. /// Invalid number of required signers.
  33. #[error("Invalid number of required signers")]
  34. InvalidNumberOfRequiredSigners,
  35. /// Instruction does not support native tokens
  36. #[error("Instruction does not support native tokens")]
  37. NativeNotSupported,
  38. /// Non-native account can only be closed if its balance is zero
  39. #[error("Non-native account can only be closed if its balance is zero")]
  40. NonNativeHasBalance,
  41. /// Invalid instruction
  42. #[error("Invalid instruction")]
  43. InvalidInstruction,
  44. /// State is invalid for requested operation.
  45. #[error("State is invalid for requested operation")]
  46. InvalidState,
  47. /// Operation overflowed
  48. #[error("Operation overflowed")]
  49. Overflow,
  50. /// Account does not support specified authority type.
  51. #[error("Account does not support specified authority type")]
  52. AuthorityTypeNotSupported,
  53. /// This token mint cannot freeze accounts.
  54. #[error("This token mint cannot freeze accounts")]
  55. MintCannotFreeze,
  56. /// Account is frozen; all account operations will fail
  57. #[error("Account is frozen")]
  58. AccountFrozen,
  59. /// Mint decimals mismatch between the client and mint
  60. #[error("The provided decimals value different from the Mint decimals")]
  61. MintDecimalsMismatch,
  62. }
  63. impl From<TokenError> for ProgramError {
  64. fn from(e: TokenError) -> Self {
  65. ProgramError::Custom(e as u32)
  66. }
  67. }
  68. impl<T> DecodeError<T> for TokenError {
  69. fn type_of() -> &'static str {
  70. "TokenError"
  71. }
  72. }