tailwind_rs_scanner/
error.rs1use thiserror::Error;
7
8#[derive(Error, Debug, Clone)]
10pub enum ScannerError {
11 #[error("File I/O error: {0}")]
12 IoError(String),
13
14 #[error("File content not available: {0}")]
15 FileContentNotAvailable(String),
16
17 #[error("Pattern matching error: {0}")]
18 PatternError(String),
19
20 #[error("Parse error: {0}")]
21 ParseError(String),
22
23 #[error("Configuration error: {0}")]
24 ConfigError(String),
25
26 #[error("Cache error: {0}")]
27 CacheError(String),
28
29 #[error("Watch error: {0}")]
30 WatchError(String),
31
32 #[error("Tree-sitter error: {0}")]
33 TreeSitterError(String),
34
35 #[error("Unsupported language: {0}")]
36 UnsupportedLanguage(String),
37
38 #[error("Generic error: {0}")]
39 Generic(String),
40}
41
42pub type Result<T> = std::result::Result<T, ScannerError>;
44
45impl From<std::io::Error> for ScannerError {
46 fn from(err: std::io::Error) -> Self {
47 ScannerError::IoError(err.to_string())
48 }
49}
50
51impl From<regex::Error> for ScannerError {
52 fn from(err: regex::Error) -> Self {
53 ScannerError::PatternError(err.to_string())
54 }
55}
56
57impl From<anyhow::Error> for ScannerError {
58 fn from(err: anyhow::Error) -> Self {
59 ScannerError::Generic(err.to_string())
60 }
61}
62
63#[cfg(test)]
64mod tests {
65 use super::*;
66
67 #[test]
68 fn test_scanner_error_creation() {
69 let error = ScannerError::IoError("File not found".to_string());
70 assert!(error.to_string().contains("File I/O error"));
71 }
72
73 #[test]
74 fn test_error_conversion() {
75 let io_error = std::io::Error::new(std::io::ErrorKind::NotFound, "File not found");
76 let scanner_error: ScannerError = io_error.into();
77 assert!(matches!(scanner_error, ScannerError::IoError(_)));
78 }
79}