Skip to main content

sd_300/
error.rs

1use thiserror::Error;
2
3/// Result type alias using AppError
4pub type Result<T> = std::result::Result<T, AppError>;
5
6/// Application-level errors for SD-300
7#[derive(Error, Debug)]
8pub enum AppError {
9    /// Failed to retrieve system information
10    #[error("Failed to retrieve system information: {message}")]
11    SystemInfo { message: String },
12
13    /// Platform-specific operation failed
14    #[error("Platform operation failed: {message}")]
15    Platform { message: String },
16
17    /// I/O operation failed
18    #[error("I/O error: {0}")]
19    Io(#[from] std::io::Error),
20
21    /// Terminal/display error
22    #[error("Display error: {message}")]
23    Display { message: String },
24
25    /// WMI error (Windows only)
26    #[cfg(windows)]
27    #[error("WMI query failed: {0}")]
28    Wmi(#[from] wmi::WMIError),
29}
30
31impl AppError {
32    pub fn system_info(message: impl Into<String>) -> Self {
33        Self::SystemInfo {
34            message: message.into(),
35        }
36    }
37
38    pub fn platform(message: impl Into<String>) -> Self {
39        Self::Platform {
40            message: message.into(),
41        }
42    }
43
44    pub fn display(message: impl Into<String>) -> Self {
45        Self::Display {
46            message: message.into(),
47        }
48    }
49}