Skip to main content

light_token/
error.rs

1//! Error types for light-token SDK.
2//!
3//! This module re-exports errors from light-compressed-token-sdk and defines
4//! additional errors specific to high-level token operations.
5
6// Re-export base errors from compressed-token-sdk
7pub use light_compressed_token_sdk::error::{Result, TokenSdkError};
8use solana_program_error::ProgramError;
9use thiserror::Error;
10
11/// Result type for light-token specific errors
12pub type LightTokenResult<T> = std::result::Result<T, LightTokenError>;
13
14/// Errors specific to high-level token operations in light-token.
15/// Error codes start at 17500 to avoid conflicts with TokenSdkError (17001-17033).
16#[derive(Debug, Error)]
17pub enum LightTokenError {
18    #[error("SPL interface required for this operation")]
19    SplInterfaceRequired,
20    #[error("Incomplete SPL interface configuration")]
21    IncompleteSplInterface,
22    #[error("Use regular SPL transfer for this operation")]
23    UseRegularSplTransfer,
24    #[error("Cannot determine account type")]
25    CannotDetermineAccountType,
26    #[error("Missing mint account")]
27    MissingMintAccount,
28    #[error("Missing SPL token program")]
29    MissingSplTokenProgram,
30    #[error("Missing SPL interface PDA")]
31    MissingSplInterfacePda,
32    #[error("Missing SPL interface PDA bump")]
33    MissingSplInterfacePdaBump,
34    #[error("SPL token program mismatch between source and destination")]
35    SplTokenProgramMismatch,
36    #[error("Invalid account data")]
37    InvalidAccountData,
38    #[error("Serialization error")]
39    SerializationError,
40    #[error("Missing CPI context account")]
41    MissingCpiContext,
42    #[error("Missing CPI authority account")]
43    MissingCpiAuthority,
44    #[error("Missing output queue account")]
45    MissingOutputQueue,
46    #[error("Missing state merkle tree account")]
47    MissingStateMerkleTree,
48    #[error("Missing address merkle tree account")]
49    MissingAddressMerkleTree,
50    #[error("Missing light system program")]
51    MissingLightSystemProgram,
52    #[error("Missing registered program PDA")]
53    MissingRegisteredProgramPda,
54    #[error("Missing account compression authority")]
55    MissingAccountCompressionAuthority,
56    #[error("Missing account compression program")]
57    MissingAccountCompressionProgram,
58    #[error("Missing system program")]
59    MissingSystemProgram,
60}
61
62impl From<LightTokenError> for ProgramError {
63    fn from(e: LightTokenError) -> Self {
64        ProgramError::Custom(e.into())
65    }
66}
67
68impl From<LightTokenError> for u32 {
69    fn from(e: LightTokenError) -> Self {
70        match e {
71            LightTokenError::SplInterfaceRequired => 17500,
72            LightTokenError::IncompleteSplInterface => 17501,
73            LightTokenError::UseRegularSplTransfer => 17502,
74            LightTokenError::CannotDetermineAccountType => 17503,
75            LightTokenError::MissingMintAccount => 17504,
76            LightTokenError::MissingSplTokenProgram => 17505,
77            LightTokenError::MissingSplInterfacePda => 17506,
78            LightTokenError::MissingSplInterfacePdaBump => 17507,
79            LightTokenError::SplTokenProgramMismatch => 17508,
80            LightTokenError::InvalidAccountData => 17509,
81            LightTokenError::SerializationError => 17510,
82            LightTokenError::MissingCpiContext => 17511,
83            LightTokenError::MissingCpiAuthority => 17512,
84            LightTokenError::MissingOutputQueue => 17513,
85            LightTokenError::MissingStateMerkleTree => 17514,
86            LightTokenError::MissingAddressMerkleTree => 17515,
87            LightTokenError::MissingLightSystemProgram => 17516,
88            LightTokenError::MissingRegisteredProgramPda => 17517,
89            LightTokenError::MissingAccountCompressionAuthority => 17518,
90            LightTokenError::MissingAccountCompressionProgram => 17519,
91            LightTokenError::MissingSystemProgram => 17520,
92        }
93    }
94}