Skip to main content

csh/log/
errors.rs

1//! Logging-related error types
2
3use std::{error::Error, fmt, io};
4
5/// Errors that can occur during logging operations
6#[derive(Debug)]
7pub enum LogError {
8    /// I/O error when writing to log files
9    IoError(io::Error),
10    /// Failed to create log directories
11    DirectoryCreationError(String),
12    /// Error formatting log messages
13    FormattingError(String),
14}
15
16impl fmt::Display for LogError {
17    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18        match self {
19            LogError::IoError(err) => write!(f, "I/O error: {}", err),
20            LogError::DirectoryCreationError(msg) => {
21                write!(f, "Failed to create directory: {}", msg)
22            }
23            LogError::FormattingError(msg) => write!(f, "Formatting error: {}", msg),
24        }
25    }
26}
27
28impl Error for LogError {}
29
30impl From<io::Error> for LogError {
31    fn from(err: io::Error) -> Self {
32        LogError::IoError(err)
33    }
34}