1use thiserror::Error;
4
5#[derive(Error, Debug)]
7pub enum SystemAnalysisError {
8    #[error("System analysis failed: {message}")]
10    AnalysisError { message: String },
11
12    #[error("System information access failed: {source}")]
14    SystemInfoError { 
15        #[source]
16        source: Box<dyn std::error::Error + Send + Sync>
17    },
18
19    #[error("Compatibility calculation failed: {message}")]
21    CompatibilityError { message: String },
22
23    #[error("Invalid workload requirements: {message}")]
25    InvalidWorkload { message: String },
26
27    #[error("Resource requirement not found: {resource_type}")]
29    ResourceNotFound { resource_type: String },
30
31    #[error("Configuration error: {message}")]
33    ConfigError { message: String },
34
35    #[error("I/O error: {0}")]
37    IoError(#[from] std::io::Error),
38
39    #[error("Serialization error: {0}")]
41    SerializationError(#[from] serde_json::Error),
42
43    #[cfg(feature = "gpu-detection")]
45    #[error("GPU detection error: {message}")]
46    GpuError { message: String },
47}
48
49impl SystemAnalysisError {
50    pub fn analysis(message: impl Into<String>) -> Self {
52        Self::AnalysisError {
53            message: message.into(),
54        }
55    }
56
57    pub fn system_info(message: impl Into<String>) -> Self {
59        Self::SystemInfoError {
60            source: Box::new(std::io::Error::new(
61                std::io::ErrorKind::Other, 
62                message.into()
63            )),
64        }
65    }
66
67    pub fn compatibility(message: impl Into<String>) -> Self {
69        Self::CompatibilityError {
70            message: message.into(),
71        }
72    }
73
74    pub fn invalid_workload(message: impl Into<String>) -> Self {
76        Self::InvalidWorkload {
77            message: message.into(),
78        }
79    }
80
81    pub fn resource_not_found(resource_type: impl Into<String>) -> Self {
83        Self::ResourceNotFound {
84            resource_type: resource_type.into(),
85        }
86    }
87
88    pub fn config(message: impl Into<String>) -> Self {
90        Self::ConfigError {
91            message: message.into(),
92        }
93    }
94
95    #[cfg(feature = "gpu-detection")]
96    pub fn gpu(message: impl Into<String>) -> Self {
98        Self::GpuError {
99            message: message.into(),
100        }
101    }
102}
103
104pub type Result<T> = std::result::Result<T, SystemAnalysisError>;