Skip to main content

rialo_feature_management_interface/
error.rs

1// Copyright (c) Subzero Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4//! Error types for the Feature Management Program
5
6use rialo_s_instruction::error::InstructionError;
7use rialo_s_program_error::{PrintProgramError, ProgramError};
8
9/// Errors that can be returned by the Feature Management Program
10///
11/// Error codes are explicitly assigned to ensure stability across versions.
12/// Do not reorder variants or change their discriminant values.
13#[derive(Debug, Clone, PartialEq, Eq)]
14#[repr(u32)]
15pub enum FeatureManagementError {
16    /// Unauthorized access - signature verification failed
17    Unauthorized = 0,
18
19    /// Invalid feature name (empty or too long)
20    InvalidFeatureName = 1,
21
22    /// Feature not found
23    FeatureNotFound = 2,
24
25    /// Invalid time range (start time >= end time)
26    InvalidTimeRange = 3,
27
28    /// Serialization error
29    SerializationError = 4,
30
31    /// Deserialization error
32    DeserializationError = 5,
33
34    /// Invalid instruction data
35    InvalidInstructionData = 6,
36
37    /// Internal error (e.g., mutex lock failure)
38    InternalError = 7,
39
40    /// Duplicate feature in modification list
41    DuplicateFeature = 8,
42
43    /// Invalid storage account (not the expected PDA)
44    InvalidStorageAccount = 9,
45
46    /// Storage account already initialized
47    AlreadyInitialized = 10,
48
49    /// Storage account not initialized
50    NotInitialized = 11,
51
52    /// `start_time_ms` or `end_time_ms` exceeds the sanity cap (`MAX_TIMESTAMP_MS`).
53    TimeOutOfRange = 12,
54
55    /// Existing sticky entry would become windowed (caller passed
56    /// `Some(end_time_ms)` over an existing `None`).
57    StickyCannotBecomeWindowed = 13,
58
59    /// Sticky entry's `start_time_ms` would move backwards.
60    StickyStartTimeBackward = 14,
61
62    /// Existing entry is in its active phase; modification rejected.
63    EntryFrozen = 15,
64
65    /// Attempted to remove an existing sticky entry.
66    StickyEntryNotRemovable = 16,
67
68    /// Maximum feature count exceeded.
69    MaxFeatureCountExceeded = 17,
70}
71
72impl From<FeatureManagementError> for ProgramError {
73    fn from(e: FeatureManagementError) -> Self {
74        ProgramError::Custom(e as u32)
75    }
76}
77
78impl From<FeatureManagementError> for InstructionError {
79    fn from(e: FeatureManagementError) -> Self {
80        InstructionError::Custom(e as u32)
81    }
82}
83
84impl PrintProgramError for FeatureManagementError {
85    fn print<E>(&self) {}
86}