Skip to main content

macos_resolver/
error.rs

1//! Error types.
2
3use thiserror::Error;
4
5/// Result alias for resolver operations.
6pub type Result<T> = std::result::Result<T, ResolverError>;
7
8/// Errors returned by resolver operations.
9#[derive(Debug, Error)]
10pub enum ResolverError {
11    /// Filesystem I/O failed (typically `PermissionDenied` on `/etc/resolver/`).
12    #[error("I/O error: {0}")]
13    Io(#[from] std::io::Error),
14
15    /// The resolver directory does not exist and could not be created.
16    #[error("resolver directory not found: {path}")]
17    DirNotFound {
18        /// The expected path.
19        path: String,
20    },
21
22    /// Attempted to remove a resolver file not managed by this crate.
23    #[error("resolver file not managed by macos-resolver: {domain}")]
24    NotManaged {
25        /// The domain whose file is unmanaged.
26        domain: String,
27    },
28
29    /// Invalid configuration values.
30    #[error("invalid config: {0}")]
31    InvalidConfig(String),
32}
33
34impl ResolverError {
35    /// Returns `true` if the underlying I/O error is `PermissionDenied`.
36    #[must_use]
37    pub fn is_permission_denied(&self) -> bool {
38        matches!(self, Self::Io(e) if e.kind() == std::io::ErrorKind::PermissionDenied)
39    }
40}