rusty_files/core/
error.rs

1use std::path::PathBuf;
2use thiserror::Error;
3
4#[derive(Debug, Error)]
5pub enum SearchError {
6    #[error("Database error: {0}")]
7    Database(#[from] rusqlite::Error),
8
9    #[error("I/O error: {0}")]
10    Io(#[from] std::io::Error),
11
12    #[error("Invalid query: {0}")]
13    InvalidQuery(String),
14
15    #[error("Path not found: {0}")]
16    PathNotFound(PathBuf),
17
18    #[error("Permission denied: {0}")]
19    PermissionDenied(PathBuf),
20
21    #[error("Index corrupted: {0}")]
22    IndexCorrupted(String),
23
24    #[error("Configuration error: {0}")]
25    Configuration(String),
26
27    #[error("Pool error: {0}")]
28    Pool(String),
29
30    #[error("Watch error: {0}")]
31    Watch(String),
32
33    #[error("Encoding error: {0}")]
34    Encoding(String),
35
36    #[error("Parse error: {0}")]
37    Parse(String),
38
39    #[error("Operation cancelled")]
40    Cancelled,
41
42    #[error("Not initialized: {0}")]
43    NotInitialized(String),
44}
45
46impl From<r2d2::Error> for SearchError {
47    fn from(err: r2d2::Error) -> Self {
48        SearchError::Pool(err.to_string())
49    }
50}
51
52impl From<notify::Error> for SearchError {
53    fn from(err: notify::Error) -> Self {
54        SearchError::Watch(err.to_string())
55    }
56}
57
58impl From<globset::Error> for SearchError {
59    fn from(err: globset::Error) -> Self {
60        SearchError::Parse(err.to_string())
61    }
62}
63
64impl From<regex::Error> for SearchError {
65    fn from(err: regex::Error) -> Self {
66        SearchError::Parse(err.to_string())
67    }
68}
69
70pub type Result<T> = std::result::Result<T, SearchError>;