1use light_account_checks::error::AccountError;
2use light_hasher::HasherError;
3use thiserror::Error;
4
5pub type Result<T> = core::result::Result<T, LightSdkTypesError>;
6
7#[derive(Debug, Error, PartialEq)]
8pub enum LightSdkTypesError {
9 #[error("Address is none during initialization")]
10 InitAddressIsNone,
11 #[error("Address is none during initialization with address")]
12 InitWithAddressIsNone,
13 #[error("Output is none during initialization with address")]
14 InitWithAddressOutputIsNone,
15 #[error("Address is none during meta mutation")]
16 MetaMutAddressIsNone,
17 #[error("Input is none during meta mutation")]
18 MetaMutInputIsNone,
19 #[error("Output lamports is none during meta mutation")]
20 MetaMutOutputLamportsIsNone,
21 #[error("Output is none during meta mutation")]
22 MetaMutOutputIsNone,
23 #[error("Address is none during meta close")]
24 MetaCloseAddressIsNone,
25 #[error("Input is none during meta close")]
26 MetaCloseInputIsNone,
27 #[error("Fewer accounts than system accounts")]
28 FewerAccountsThanSystemAccounts,
29 #[error("CPI accounts index out of bounds: {0}")]
30 CpiAccountsIndexOutOfBounds(usize),
31 #[error("Invalid CPI context account")]
32 InvalidCpiContextAccount,
33 #[error("Invalid sol pool pda account")]
34 InvalidSolPoolPdaAccount,
35 #[error("CpigAccounts accounts slice starts with an invalid account. It should start with LightSystemProgram SySTEM1eSU2p4BGQfQpimFEWWSC1XDFeun3Nqzz3rT7.")]
36 InvalidCpiAccountsOffset,
37 #[error(transparent)]
38 AccountError(#[from] AccountError),
39 #[error(transparent)]
40 Hasher(#[from] HasherError),
41}
42
43impl From<LightSdkTypesError> for u32 {
44 fn from(e: LightSdkTypesError) -> Self {
45 match e {
46 LightSdkTypesError::InitAddressIsNone => 14021,
47 LightSdkTypesError::InitWithAddressIsNone => 14022,
48 LightSdkTypesError::InitWithAddressOutputIsNone => 14023,
49 LightSdkTypesError::MetaMutAddressIsNone => 14024,
50 LightSdkTypesError::MetaMutInputIsNone => 14025,
51 LightSdkTypesError::MetaMutOutputLamportsIsNone => 14026,
52 LightSdkTypesError::MetaMutOutputIsNone => 14027,
53 LightSdkTypesError::MetaCloseAddressIsNone => 14028,
54 LightSdkTypesError::MetaCloseInputIsNone => 14029,
55 LightSdkTypesError::FewerAccountsThanSystemAccounts => 14017,
56 LightSdkTypesError::CpiAccountsIndexOutOfBounds(_) => 14031,
57 LightSdkTypesError::InvalidCpiContextAccount => 14032,
58 LightSdkTypesError::InvalidSolPoolPdaAccount => 14033,
59 LightSdkTypesError::InvalidCpiAccountsOffset => 14034,
60 LightSdkTypesError::AccountError(e) => e.into(),
61 LightSdkTypesError::Hasher(e) => e.into(),
62 }
63 }
64}