rialo_feature_management_enforcement_interface/error.rs
1// Copyright (c) Subzero Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4//! Error types for the Feature Management Enforcement Program.
5
6use rialo_s_instruction::error::InstructionError;
7use rialo_s_program_error::{PrintProgramError, ProgramError};
8
9/// Errors returned by the Feature Management Enforcement Program.
10///
11/// **Stable from this commit forward.** Discriminants surface as
12/// `ProgramError::Custom(u32)` over the wire. Add new variants only at the
13/// tail with the next unused discriminant.
14#[derive(Debug, Clone, PartialEq, Eq)]
15#[repr(u32)]
16pub enum EnforcementError {
17 /// Caller is not the policy program's decision-authority PDA.
18 UnauthorizedInvoker = 0,
19
20 /// Invalid feature name (empty, too long, or disallowed characters).
21 InvalidFeatureName = 1,
22
23 /// Serialization error.
24 SerializationError = 2,
25
26 /// Deserialization error.
27 DeserializationError = 3,
28
29 /// Invalid instruction data.
30 InvalidInstructionData = 4,
31
32 /// Invalid storage account (not the expected PDA).
33 InvalidStorageAccount = 5,
34
35 /// Storage account already initialized.
36 AlreadyInitialized = 6,
37
38 /// Storage account not initialized.
39 NotInitialized = 7,
40
41 /// `MAX_FEATURE_COUNT` exceeded.
42 MaxFeatureCountExceeded = 8,
43
44 /// Serialized state would exceed `MAX_ENFORCEMENT_STATE_SIZE`.
45 EnforcementStateTooLarge = 9,
46}
47
48impl From<EnforcementError> for ProgramError {
49 fn from(e: EnforcementError) -> Self {
50 ProgramError::Custom(e as u32)
51 }
52}
53
54impl From<EnforcementError> for InstructionError {
55 fn from(e: EnforcementError) -> Self {
56 InstructionError::Custom(e as u32)
57 }
58}
59
60impl PrintProgramError for EnforcementError {
61 fn print<E>(&self) {}
62}