Skip to main content

lightcone_sdk/program/
error.rs

1//! Error types for the Lightcone on-chain program module.
2
3use thiserror::Error;
4
5#[cfg(feature = "client")]
6use solana_client::client_error::ClientError;
7
8/// SDK-specific errors
9#[derive(Debug, Error)]
10pub enum SdkError {
11    /// RPC client error
12    #[cfg(feature = "client")]
13    #[error("RPC error: {0}")]
14    Rpc(#[from] ClientError),
15
16    /// Invalid account discriminator
17    #[error("Invalid account discriminator: expected {expected}, got {actual}")]
18    InvalidDiscriminator { expected: String, actual: String },
19
20    /// Account not found
21    #[error("Account not found: {0}")]
22    AccountNotFound(String),
23
24    /// Invalid data length
25    #[error("Invalid data length: expected {expected}, got {actual}")]
26    InvalidDataLength { expected: usize, actual: usize },
27
28    /// Invalid outcome count
29    #[error("Invalid outcome count: {count} (must be {min}-{max})", min = crate::program::constants::MIN_OUTCOMES, max = crate::program::constants::MAX_OUTCOMES)]
30    InvalidOutcomeCount { count: u8 },
31
32    /// Invalid outcome index
33    #[error("Invalid outcome index: {index} (max {max})")]
34    InvalidOutcomeIndex { index: u8, max: u8 },
35
36    /// Too many makers
37    #[error("Too many makers: {count} (max {max})", max = crate::program::constants::MAX_MAKERS)]
38    TooManyMakers { count: usize },
39
40    #[error("Signature verification failed")]
41    SignatureVerificationFailed,
42
43    #[error("Invalid signature")]
44    InvalidSignature,
45
46    /// Serialization error
47    #[error("Serialization error: {0}")]
48    Serialization(String),
49
50    /// Invalid side value
51    #[error("Invalid side value: {0} (must be 0 or 1)")]
52    InvalidSide(u8),
53
54    /// Invalid market status
55    #[error("Invalid market status: {0}")]
56    InvalidMarketStatus(u8),
57
58    /// Missing required field
59    #[error("Missing required field: {0}")]
60    MissingField(String),
61
62    /// Arithmetic overflow
63    #[error("Arithmetic overflow")]
64    Overflow,
65
66    /// Invalid pubkey
67    #[error("Invalid pubkey: {0}")]
68    InvalidPubkey(String),
69
70    /// Scaling error (price/size conversion)
71    #[error("Scaling error: {0}")]
72    Scaling(#[from] crate::shared::scaling::ScalingError),
73}
74
75/// Result type alias for SDK operations
76pub type SdkResult<T> = Result<T, SdkError>;