rialo-feature-management-program-interface 0.8.0-alpha.0

Rialo Feature Management Program Interface
Documentation
// Copyright (c) Subzero Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

//! Error types for the Feature Management Program

use rialo_s_instruction::error::InstructionError;
use rialo_s_program_error::{PrintProgramError, ProgramError};

/// Errors that can be returned by the Feature Management Program
///
/// Error codes are explicitly assigned to ensure stability across versions.
/// Do not reorder variants or change their discriminant values.
#[derive(Debug, Clone, PartialEq, Eq)]
#[repr(u32)]
pub enum FeatureManagementError {
    /// Unauthorized access - signature verification failed
    Unauthorized = 0,

    /// Invalid feature name (empty or too long)
    InvalidFeatureName = 1,

    /// Feature not found
    FeatureNotFound = 2,

    /// Invalid time range (start time >= end time)
    InvalidTimeRange = 3,

    /// Serialization error
    SerializationError = 4,

    /// Deserialization error
    DeserializationError = 5,

    /// Invalid instruction data
    InvalidInstructionData = 6,

    /// Internal error (e.g., mutex lock failure)
    InternalError = 7,

    /// Duplicate feature in modification list
    DuplicateFeature = 8,

    /// Invalid storage account (not the expected PDA)
    InvalidStorageAccount = 9,

    /// Storage account already initialized
    AlreadyInitialized = 10,

    /// Storage account not initialized
    NotInitialized = 11,

    /// `start_time_ms` or `end_time_ms` exceeds the sanity cap (`MAX_TIMESTAMP_MS`).
    TimeOutOfRange = 12,

    /// Existing sticky entry would become windowed (caller passed
    /// `Some(end_time_ms)` over an existing `None`).
    StickyCannotBecomeWindowed = 13,

    /// Sticky entry's `start_time_ms` would move backwards.
    StickyStartTimeBackward = 14,

    /// Existing entry is in its active phase; modification rejected.
    EntryFrozen = 15,

    /// Attempted to remove an existing sticky entry.
    StickyEntryNotRemovable = 16,

    /// Maximum feature count exceeded.
    MaxFeatureCountExceeded = 17,
}

impl From<FeatureManagementError> for ProgramError {
    fn from(e: FeatureManagementError) -> Self {
        ProgramError::Custom(e as u32)
    }
}

impl From<FeatureManagementError> for InstructionError {
    fn from(e: FeatureManagementError) -> Self {
        InstructionError::Custom(e as u32)
    }
}

impl PrintProgramError for FeatureManagementError {
    fn print<E>(&self) {}
}