nullnet_libconfmon/
error.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use std::fmt::{Display, Formatter, Result};

/// Represents the different kinds of errors that can occur during configuration monitoring.
#[derive(Debug, Clone)]
pub enum ErrorKind {
    ErrorInitializingWatcher,
    ErrorWatchingFile,
    ErrorReadingFile,
    ErrorHandlingSnapshot,
    ErrorUnsupportedPlatform,
}

impl Display for ErrorKind {
    /// Formats the `ErrorKind` for display.
    fn fmt(&self, f: &mut Formatter) -> Result {
        match self {
            ErrorKind::ErrorInitializingWatcher => write!(f, "ErrorInitializingWatcher"),
            ErrorKind::ErrorWatchingFile => write!(f, "ErrorWatchingFile"),
            ErrorKind::ErrorReadingFile => write!(f, "ErrorReadingFile"),
            ErrorKind::ErrorHandlingSnapshot => write!(f, "ErrorHandlingSnapshot"),
            ErrorKind::ErrorUnsupportedPlatform => write!(f, "ErrorUnsupportedPlatform"),
        }
    }
}

/// A structured error type for `libconfmon`.
///
/// # Fields
/// - `kind`: The specific type of error.
/// - `message`: A detailed message explaining the error.
#[derive(Debug, Clone)]
pub struct Error {
    pub kind: ErrorKind,
    pub message: String,
}

impl Display for Error {
    /// Formats the `Error` for display.
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "[{}] {}", self.kind, self.message)
    }
}