vidsage-core 0.1.0

Core functionality for VidSage video processing and AI commentary generation
Documentation
//! Core error definitions

use serde::{Deserialize, Serialize};
use thiserror::Error;

/// Core error enumeration
#[derive(Error, Debug, Serialize, Deserialize)]
pub enum CoreError {
    #[error("Video processing error: {0}")]
    VideoProcessingError(String),

    #[error("AI commentary generation error: {0}")]
    CommentaryError(String),

    #[error("Storage error: {0}")]
    StorageError(#[from] crate::storage::StorageError),

    #[error("Configuration error: {0}")]
    ConfigError(#[from] crate::config::ConfigError),

    #[error("Invalid input: {0}")]
    InvalidInput(String),

    #[error("Unauthorized access")]
    Unauthorized,

    #[error("Forbidden access")]
    Forbidden,

    #[error("Resource not found: {0}")]
    NotFound(String),

    #[error("Internal server error: {0}")]
    InternalError(String),

    #[error("Network error: {0}")]
    NetworkError(String),

    #[error("Timeout error")]
    Timeout,

    #[error("Serialization error: {0}")]
    SerializationError(String),

    #[error("Deserialization error: {0}")]
    DeserializationError(String),

    #[error("IO error: {0}")]
    IoError(String),

    #[error("JSON serialization error: {0}")]
    JsonError(String),
}

/// Result type for core functionality
pub type Result<T> = std::result::Result<T, CoreError>;

impl CoreError {
    /// Create a new VideoProcessingError
    pub fn video_processing_error(msg: &str) -> Self {
        CoreError::VideoProcessingError(msg.to_string())
    }

    /// Create a new CommentaryError
    pub fn commentary_error(msg: &str) -> Self {
        CoreError::CommentaryError(msg.to_string())
    }

    /// Create a new InvalidInput error
    pub fn invalid_input(msg: &str) -> Self {
        CoreError::InvalidInput(msg.to_string())
    }

    /// Create a new NotFound error
    pub fn not_found(resource: &str) -> Self {
        CoreError::NotFound(resource.to_string())
    }

    /// Create a new InternalError
    pub fn internal_error(msg: &str) -> Self {
        CoreError::InternalError(msg.to_string())
    }

    /// Create a new NetworkError
    pub fn network_error(msg: &str) -> Self {
        CoreError::NetworkError(msg.to_string())
    }

    /// Create a new SerializationError
    pub fn serialization_error(msg: &str) -> Self {
        CoreError::SerializationError(msg.to_string())
    }

    /// Create a new DeserializationError
    pub fn deserialization_error(msg: &str) -> Self {
        CoreError::DeserializationError(msg.to_string())
    }

    /// Create a new IoError
    pub fn io_error(msg: &str) -> Self {
        CoreError::IoError(msg.to_string())
    }

    /// Create a new JsonError
    pub fn json_error(msg: &str) -> Self {
        CoreError::JsonError(msg.to_string())
    }
}