qml_rs/
error.rs

1//! Error types for QML Rust.
2//!
3//! This module provides comprehensive error handling for all QML operations,
4//! using the thiserror crate for ergonomic error handling.
5
6use thiserror::Error;
7
8/// The main error type for QML operations.
9///
10/// This enum covers all possible errors that can occur during job processing,
11/// storage operations, and serialization.
12#[derive(Error, Debug, Clone, PartialEq)]
13pub enum QmlError {
14    /// Job not found error
15    #[error("Job not found: {job_id}")]
16    JobNotFound { job_id: String },
17
18    /// Serialization/deserialization errors
19    #[error("Serialization failed: {message}")]
20    SerializationError { message: String },
21
22    /// Storage-related errors
23    #[error("Storage error: {message}")]
24    StorageError { message: String },
25
26    /// Invalid job state transition
27    #[error("Invalid state transition from {from} to {to}")]
28    InvalidStateTransition { from: String, to: String },
29
30    /// Invalid job data
31    #[error("Invalid job data: {message}")]
32    InvalidJobData { message: String },
33
34    /// Queue operation errors
35    #[error("Queue operation failed: {message}")]
36    QueueError { message: String },
37
38    /// Worker-related errors
39    #[error("Worker error: {message}")]
40    WorkerError { message: String },
41
42    /// Configuration errors
43    #[error("Configuration error: {message}")]
44    ConfigurationError { message: String },
45
46    /// Timeout errors
47    #[error("Operation timed out: {operation}")]
48    TimeoutError { operation: String },
49
50    /// Database migration errors
51    #[error("Migration error: {message}")]
52    MigrationError { message: String },
53}
54
55impl From<serde_json::Error> for QmlError {
56    fn from(err: serde_json::Error) -> Self {
57        QmlError::SerializationError {
58            message: err.to_string(),
59        }
60    }
61}
62
63impl From<uuid::Error> for QmlError {
64    fn from(err: uuid::Error) -> Self {
65        QmlError::InvalidJobData {
66            message: format!("UUID error: {}", err),
67        }
68    }
69}
70
71/// A specialized Result type for QML operations.
72pub type Result<T> = std::result::Result<T, QmlError>;