Skip to main content

spherenet_program_whitelist_interface/
error.rs

1//! Error types
2
3use pinocchio::program_error::ProgramError;
4
5/// Errors that may be returned by the Program Whitelist program.
6///
7/// Discriminants use a hex sentinel base (cf. vw's `0xAAAAAA00`): a visually
8/// recognizable marker that keeps these `ProgramError::Custom` codes clear of
9/// framework/system ranges. The base differs from vw's so the two programs'
10/// custom codes never collide. Bare variants auto-increment from the base.
11#[repr(u32)]
12#[derive(thiserror::Error, Clone, Debug, Eq, PartialEq)]
13pub enum ProgramWhitelistError {
14    // --- Authentication / account validation (the shared auth-door surface) ---
15    /// The account is not the canonical program whitelist account.
16    #[error("Invalid program whitelist account")]
17    InvalidProgramWhitelistAccount = 0xBBBBBB00,
18
19    /// The signer does not match the pending authority.
20    #[error("Pending authority mismatch")]
21    PendingAuthorityMismatch, // 0xBBBBBB01
22
23    /// No pending authority.
24    #[error("No pending authority")]
25    NoPendingAuthority, // 0xBBBBBB02
26
27    /// An authority transfer is already in flight; it must be cancelled before
28    /// another can be initiated.
29    #[error("Authority transfer already initialized")]
30    AuthorityTransferAlreadyInitialized, // 0xBBBBBB03
31
32    // --- Entry-account validation (the entry-side door surface) ---
33    /// The account is not the canonical whitelist entry PDA for the deployer.
34    #[error("Invalid program whitelist entry account")]
35    InvalidProgramWhitelistEntryAccount, // 0xBBBBBB04
36
37    /// The whitelist entry account is not owned by the program whitelist
38    /// program.
39    #[error("Invalid program whitelist entry account owner")]
40    InvalidProgramWhitelistEntryAccountOwner, // 0xBBBBBB05
41
42    // --- Program-specific ---
43    /// The deployer is not approved (whitelist entry is pending approval).
44    #[error("Deployer not approved")]
45    DeployerNotApproved, // 0xBBBBBB06
46
47    /// The whitelist entry is not pending approval.
48    #[error("Whitelist entry is not pending")]
49    NotPending, // 0xBBBBBB07
50}
51
52impl From<ProgramWhitelistError> for ProgramError {
53    fn from(e: ProgramWhitelistError) -> Self {
54        ProgramError::Custom(e as u32)
55    }
56}
57
58#[cfg(test)]
59mod tests {
60    use super::ProgramWhitelistError;
61
62    /// Pin every discriminant to its hex-sentinel value. The variants are bare
63    /// (auto-incrementing) for readability; this test is what makes a reorder or
64    /// insertion that shifts a code fail loudly here, instead of silently
65    /// diverging from the generated clients (which pin all values explicitly).
66    #[test]
67    fn error_discriminants_are_pinned() {
68        assert_eq!(
69            ProgramWhitelistError::InvalidProgramWhitelistAccount as u32,
70            0xBBBBBB00
71        );
72        assert_eq!(
73            ProgramWhitelistError::PendingAuthorityMismatch as u32,
74            0xBBBBBB01
75        );
76        assert_eq!(
77            ProgramWhitelistError::NoPendingAuthority as u32,
78            0xBBBBBB02
79        );
80        assert_eq!(
81            ProgramWhitelistError::AuthorityTransferAlreadyInitialized as u32,
82            0xBBBBBB03
83        );
84        assert_eq!(
85            ProgramWhitelistError::InvalidProgramWhitelistEntryAccount as u32,
86            0xBBBBBB04
87        );
88        assert_eq!(
89            ProgramWhitelistError::InvalidProgramWhitelistEntryAccountOwner as u32,
90            0xBBBBBB05
91        );
92        assert_eq!(
93            ProgramWhitelistError::DeployerNotApproved as u32,
94            0xBBBBBB06
95        );
96        assert_eq!(ProgramWhitelistError::NotPending as u32, 0xBBBBBB07);
97    }
98}