Skip to main content

oxigdal_mobile_enhanced/
error.rs

1//! Error types for mobile-enhanced operations
2
3use thiserror::Error;
4
5/// Result type alias using MobileError
6pub type Result<T> = core::result::Result<T, MobileError>;
7
8/// Errors that can occur in mobile-enhanced operations
9#[derive(Debug, Error)]
10pub enum MobileError {
11    /// Battery monitoring is not supported on this platform
12    #[error("Battery monitoring is not supported on this platform")]
13    BatteryMonitoringNotSupported,
14
15    /// Failed to read battery information
16    #[error("Failed to read battery information: {0}")]
17    BatteryReadError(String),
18
19    /// Network optimization failed
20    #[error("Network optimization failed: {0}")]
21    NetworkOptimizationError(String),
22
23    /// Compression failed
24    #[error("Compression failed: {0}")]
25    CompressionError(String),
26
27    /// Decompression failed
28    #[error("Decompression failed: {0}")]
29    DecompressionError(String),
30
31    /// Background task scheduling failed
32    #[error("Background task scheduling failed: {0}")]
33    BackgroundTaskError(String),
34
35    /// Storage operation failed
36    #[error("Storage operation failed: {0}")]
37    StorageError(String),
38
39    /// Cache operation failed
40    #[error("Cache operation failed: {0}")]
41    CacheError(String),
42
43    /// Memory pressure handling failed
44    #[error("Memory pressure handling failed: {0}")]
45    MemoryPressureError(String),
46
47    /// Platform-specific operation failed
48    #[error("Platform-specific operation failed: {0}")]
49    PlatformError(String),
50
51    /// Invalid configuration
52    #[error("Invalid configuration: {0}")]
53    InvalidConfiguration(String),
54
55    /// Feature not available
56    #[error("Feature not available: {0}")]
57    FeatureNotAvailable(String),
58
59    /// I/O error
60    #[error("I/O error: {0}")]
61    IoError(#[from] std::io::Error),
62
63    /// Serialization error
64    #[error("Serialization error: {0}")]
65    SerializationError(#[from] serde_json::Error),
66
67    /// Core library error
68    #[error("Core library error: {0}")]
69    CoreError(String),
70}
71
72impl From<oxigdal_core::error::OxiGdalError> for MobileError {
73    fn from(err: oxigdal_core::error::OxiGdalError) -> Self {
74        Self::CoreError(err.to_string())
75    }
76}
77
78#[cfg(test)]
79mod tests {
80    use super::*;
81
82    #[test]
83    fn test_error_display() {
84        let err = MobileError::BatteryMonitoringNotSupported;
85        assert!(err.to_string().contains("Battery monitoring"));
86
87        let err = MobileError::NetworkOptimizationError("test".to_string());
88        assert!(err.to_string().contains("Network optimization"));
89        assert!(err.to_string().contains("test"));
90    }
91
92    #[test]
93    fn test_error_from_io() {
94        let io_err = std::io::Error::new(std::io::ErrorKind::NotFound, "file not found");
95        let mobile_err: MobileError = io_err.into();
96        assert!(mobile_err.to_string().contains("I/O error"));
97    }
98
99    #[test]
100    fn test_result_type() {
101        let ok_result: Result<i32> = Ok(42);
102        assert_eq!(ok_result.ok(), Some(42));
103
104        let err_result: Result<i32> = Err(MobileError::BatteryMonitoringNotSupported);
105        assert!(err_result.is_err());
106    }
107}