fogo_sessions_sdk/
error.rs1use solana_program::program_error::ProgramError;
2use thiserror::Error;
3
4#[derive(Error, Debug, Clone)]
5pub enum SessionError {
6 #[error("This session has expired")]
7 Expired,
8 #[error("This session was created for a different user")]
9 UserMismatch,
10 #[error("This session was created for a different program")]
11 UnauthorizedProgram,
12 #[error("A required program signer appears as a non-signer")]
13 MissingRequiredSignature,
14 #[error("There was an error loading the clock sysvar")]
15 ClockError,
16 #[error("A session account failed to deserialize")]
17 InvalidAccountData,
18 #[error("A session account has the wrong discriminator")]
19 InvalidAccountDiscriminator,
20 #[error("A session account has the wrong version")]
21 InvalidAccountVersion,
22 #[error("This transfer exceeds your session limits")]
23 LimitsExceeded,
24 #[error("This session was revoked")]
25 Revoked,
26 #[error("A session can only send rent to its user account when closing a token account")]
27 TokenCloseAccountWrongDestination,
28}
29
30impl From<SessionError> for u32 {
31 fn from(err: SessionError) -> u32 {
32 match err {
33 SessionError::Expired => 4_000_000_000,
34 SessionError::UserMismatch => 4_000_000_001,
35 SessionError::UnauthorizedProgram => 4_000_000_002,
36 SessionError::MissingRequiredSignature => 4_000_000_003,
37 SessionError::ClockError => 4_000_000_004,
38 SessionError::InvalidAccountData => 4_000_000_005,
39 SessionError::InvalidAccountDiscriminator => 4_000_000_006,
40 SessionError::InvalidAccountVersion => 4_000_000_007,
41 SessionError::LimitsExceeded => 4_000_000_008,
42 SessionError::Revoked => 4_000_000_009,
43 SessionError::TokenCloseAccountWrongDestination => 4_000_000_010,
44 }
45 }
46}
47
48impl From<SessionError> for ProgramError {
49 fn from(err: SessionError) -> Self {
50 Self::Custom(err.into())
51 }
52}
53
54#[cfg(feature = "anchor")]
55impl From<SessionError> for anchor_lang::error::Error {
56 fn from(err: SessionError) -> Self {
57 Into::<ProgramError>::into(err).into()
58 }
59}