FreedomLogger/error/types.rs
1// File: src/error/types.rs
2
3/*
4Error types for FreedomLogger internal operations.
5These errors represents failures that can occur within the logger itself.
6When these errors occur, they are silently handled and optionally.
7Written to a separate error log fie for debugging.
8 */
9use std::fmt;
10
11/// Represents all possible internal failures of the FreedomLogger.
12#[derive(Debug, Clone, PartialEq)]
13pub enum LoggerError {
14 /*
15 Failed to create the log file
16 Occurs when: file doesn't exist and creation fails
17 */
18 FileCreationFailed {
19 path: String,
20 reason: String,
21 },
22
23 /*
24 Failed to create the necessary directories
25 Occurs when: directory doesn't exist and creation fails
26 */
27 DirectoryCreationFailed {
28 path: String,
29 reason: String,
30 },
31
32 /*
33 Not enough permissions to write to log file
34 Occurs when: file exists but can't write to it
35 */
36 WritePermissionDenied {
37 path: String,
38 },
39
40 /*
41 Disk space insufficient for writing
42 Occurs when: write operation fails due disk full
43 */
44 DiskFull {
45 path: String,
46 bytes_attempted: usize,
47 },
48
49 /*
50 Log rotation operation failed
51 Occurs when: log rotation fails
52 */
53 RotationFailed {
54 current_file: String,
55 backup_file: String,
56 reason: String,
57 },
58}
59
60impl fmt::Display for LoggerError {
61 /*
62 Human-readable error messages for debugging
63 These will be written to the error log file.
64 */
65 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
66 match self {
67 LoggerError::FileCreationFailed {path, reason} => {
68 write!(f, "Failed to create log file '{}' : {}", path, reason)
69 }
70 LoggerError::DirectoryCreationFailed {path,reason} => {
71 write!(f, "Failed to create directory '{}': {}", path, reason)
72 }
73
74 LoggerError::WritePermissionDenied {path} => {
75 write!(f, "Persmission denied writing to '{}'", path)
76 }
77
78 LoggerError::DiskFull {path, bytes_attempted} => {
79 write!(f, "Disk full: could not write {} bytes to '{}'", bytes_attempted, path)
80 }
81
82 LoggerError::RotationFailed {current_file, backup_file, reason} => {
83 write!(f, "Log rotation failed: '{}' -> '{}': {}", current_file, backup_file, reason)
84 }
85 }
86 }
87}
88
89impl std::error::Error for LoggerError {}
90
91/*
92Result type for logging operations
93Used internally - user never sees this result
94 */
95pub type LoggerResult<T> = Result<T, LoggerError>;