oxigdal_mobile_enhanced/
error.rs1use thiserror::Error;
4
5pub type Result<T> = core::result::Result<T, MobileError>;
7
8#[derive(Debug, Error)]
10pub enum MobileError {
11 #[error("Battery monitoring is not supported on this platform")]
13 BatteryMonitoringNotSupported,
14
15 #[error("Failed to read battery information: {0}")]
17 BatteryReadError(String),
18
19 #[error("Network optimization failed: {0}")]
21 NetworkOptimizationError(String),
22
23 #[error("Compression failed: {0}")]
25 CompressionError(String),
26
27 #[error("Decompression failed: {0}")]
29 DecompressionError(String),
30
31 #[error("Background task scheduling failed: {0}")]
33 BackgroundTaskError(String),
34
35 #[error("Storage operation failed: {0}")]
37 StorageError(String),
38
39 #[error("Cache operation failed: {0}")]
41 CacheError(String),
42
43 #[error("Memory pressure handling failed: {0}")]
45 MemoryPressureError(String),
46
47 #[error("Platform-specific operation failed: {0}")]
49 PlatformError(String),
50
51 #[error("Invalid configuration: {0}")]
53 InvalidConfiguration(String),
54
55 #[error("Feature not available: {0}")]
57 FeatureNotAvailable(String),
58
59 #[error("I/O error: {0}")]
61 IoError(#[from] std::io::Error),
62
63 #[error("Serialization error: {0}")]
65 SerializationError(#[from] serde_json::Error),
66
67 #[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}