unistore_watcher/
error.rs

1//! 【错误类型】- 文件监控相关错误定义
2//!
3//! 职责:
4//! - 定义监控操作的错误类型
5//! - 提供错误转换
6
7use crate::deps::PathBuf;
8use thiserror::Error;
9
10/// 文件监控错误
11#[derive(Debug, Error)]
12pub enum WatcherError {
13    /// 路径不存在
14    #[error("路径不存在: {0}")]
15    PathNotFound(PathBuf),
16
17    /// 路径已被监控
18    #[error("路径已被监控: {0}")]
19    AlreadyWatched(PathBuf),
20
21    /// 路径未被监控
22    #[error("路径未被监控: {0}")]
23    NotWatched(PathBuf),
24
25    /// 监控器已关闭
26    #[error("监控器已关闭")]
27    WatcherClosed,
28
29    /// 底层 notify 错误
30    #[error("监控错误: {0}")]
31    NotifyError(#[from] notify::Error),
32
33    /// 通道发送错误
34    #[error("事件发送失败")]
35    SendError,
36
37    /// 初始化失败
38    #[error("监控器初始化失败: {0}")]
39    InitError(String),
40}
41
42impl WatcherError {
43    /// 检查是否是路径不存在错误
44    pub fn is_not_found(&self) -> bool {
45        matches!(self, Self::PathNotFound(_))
46    }
47
48    /// 检查是否是已监控错误
49    pub fn is_already_watched(&self) -> bool {
50        matches!(self, Self::AlreadyWatched(_))
51    }
52}