nullnet_libconfmon/
error.rs

1use std::fmt::{Display, Formatter, Result};
2
3/// Represents the different kinds of errors that can occur during configuration monitoring.
4#[derive(Debug, Clone)]
5pub enum ErrorKind {
6    ErrorInitializingWatcher,
7    ErrorWatchingFile,
8    ErrorReadingFile,
9    ErrorHandlingSnapshot,
10    ErrorUnsupportedPlatform,
11}
12
13impl Display for ErrorKind {
14    /// Formats the `ErrorKind` for display.
15    fn fmt(&self, f: &mut Formatter) -> Result {
16        match self {
17            ErrorKind::ErrorInitializingWatcher => write!(f, "ErrorInitializingWatcher"),
18            ErrorKind::ErrorWatchingFile => write!(f, "ErrorWatchingFile"),
19            ErrorKind::ErrorReadingFile => write!(f, "ErrorReadingFile"),
20            ErrorKind::ErrorHandlingSnapshot => write!(f, "ErrorHandlingSnapshot"),
21            ErrorKind::ErrorUnsupportedPlatform => write!(f, "ErrorUnsupportedPlatform"),
22        }
23    }
24}
25
26/// A structured error type for `libconfmon`.
27///
28/// # Fields
29/// - `kind`: The specific type of error.
30/// - `message`: A detailed message explaining the error.
31#[derive(Debug, Clone)]
32pub struct Error {
33    pub kind: ErrorKind,
34    pub message: String,
35}
36
37impl Display for Error {
38    /// Formats the `Error` for display.
39    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40        write!(f, "[{}] {}", self.kind, self.message)
41    }
42}