Skip to main content

vidsage_core/
error.rs

1//! Core error definitions
2
3use serde::{Deserialize, Serialize};
4use thiserror::Error;
5
6/// Core error enumeration
7#[derive(Error, Debug, Serialize, Deserialize)]
8pub enum CoreError {
9    #[error("Video processing error: {0}")]
10    VideoProcessingError(String),
11
12    #[error("AI commentary generation error: {0}")]
13    CommentaryError(String),
14
15    #[error("Storage error: {0}")]
16    StorageError(#[from] crate::storage::StorageError),
17
18    #[error("Configuration error: {0}")]
19    ConfigError(#[from] crate::config::ConfigError),
20
21    #[error("Invalid input: {0}")]
22    InvalidInput(String),
23
24    #[error("Unauthorized access")]
25    Unauthorized,
26
27    #[error("Forbidden access")]
28    Forbidden,
29
30    #[error("Resource not found: {0}")]
31    NotFound(String),
32
33    #[error("Internal server error: {0}")]
34    InternalError(String),
35
36    #[error("Network error: {0}")]
37    NetworkError(String),
38
39    #[error("Timeout error")]
40    Timeout,
41
42    #[error("Serialization error: {0}")]
43    SerializationError(String),
44
45    #[error("Deserialization error: {0}")]
46    DeserializationError(String),
47
48    #[error("IO error: {0}")]
49    IoError(String),
50
51    #[error("JSON serialization error: {0}")]
52    JsonError(String),
53}
54
55/// Result type for core functionality
56pub type Result<T> = std::result::Result<T, CoreError>;
57
58impl CoreError {
59    /// Create a new VideoProcessingError
60    pub fn video_processing_error(msg: &str) -> Self {
61        CoreError::VideoProcessingError(msg.to_string())
62    }
63
64    /// Create a new CommentaryError
65    pub fn commentary_error(msg: &str) -> Self {
66        CoreError::CommentaryError(msg.to_string())
67    }
68
69    /// Create a new InvalidInput error
70    pub fn invalid_input(msg: &str) -> Self {
71        CoreError::InvalidInput(msg.to_string())
72    }
73
74    /// Create a new NotFound error
75    pub fn not_found(resource: &str) -> Self {
76        CoreError::NotFound(resource.to_string())
77    }
78
79    /// Create a new InternalError
80    pub fn internal_error(msg: &str) -> Self {
81        CoreError::InternalError(msg.to_string())
82    }
83
84    /// Create a new NetworkError
85    pub fn network_error(msg: &str) -> Self {
86        CoreError::NetworkError(msg.to_string())
87    }
88
89    /// Create a new SerializationError
90    pub fn serialization_error(msg: &str) -> Self {
91        CoreError::SerializationError(msg.to_string())
92    }
93
94    /// Create a new DeserializationError
95    pub fn deserialization_error(msg: &str) -> Self {
96        CoreError::DeserializationError(msg.to_string())
97    }
98
99    /// Create a new IoError
100    pub fn io_error(msg: &str) -> Self {
101        CoreError::IoError(msg.to_string())
102    }
103
104    /// Create a new JsonError
105    pub fn json_error(msg: &str) -> Self {
106        CoreError::JsonError(msg.to_string())
107    }
108}