Skip to main content

ecl_adapter_fs/
error.rs

1//! Error types for the filesystem adapter.
2
3use thiserror::Error;
4
5/// Errors specific to the filesystem adapter.
6#[derive(Debug, Error)]
7#[non_exhaustive]
8pub enum FsAdapterError {
9    /// An I/O error occurred during file operations.
10    #[error("filesystem I/O error: {0}")]
11    Io(#[from] std::io::Error),
12
13    /// A glob pattern was invalid.
14    #[error("invalid glob pattern '{pattern}': {message}")]
15    InvalidPattern {
16        /// The invalid pattern.
17        pattern: String,
18        /// Error detail.
19        message: String,
20    },
21}
22
23#[cfg(test)]
24mod tests {
25    use super::*;
26
27    #[test]
28    fn test_fs_adapter_error_display_io() {
29        let err = FsAdapterError::Io(std::io::Error::new(
30            std::io::ErrorKind::NotFound,
31            "file not found",
32        ));
33        assert!(err.to_string().contains("file not found"));
34    }
35
36    #[test]
37    fn test_fs_adapter_error_display_invalid_pattern() {
38        let err = FsAdapterError::InvalidPattern {
39            pattern: "[bad".to_string(),
40            message: "unclosed bracket".to_string(),
41        };
42        let msg = err.to_string();
43        assert!(msg.contains("[bad"));
44        assert!(msg.contains("unclosed bracket"));
45    }
46
47    #[test]
48    fn test_fs_adapter_error_from_io() {
49        let io_err = std::io::Error::new(std::io::ErrorKind::PermissionDenied, "denied");
50        let err: FsAdapterError = io_err.into();
51        assert!(matches!(err, FsAdapterError::Io(_)));
52    }
53
54    #[test]
55    fn test_fs_adapter_error_implements_send_sync() {
56        fn assert_send_sync<T: Send + Sync>() {}
57        assert_send_sync::<FsAdapterError>();
58    }
59}