Overview
The Error Handler module provides centralized exception management, comprehensive logging, and user-friendly error display functionality. It implements NIST SP 800-53 Rev. 5 security controls for audit logging and error handling.NIST SP 800-53 Rev. 5 Controls
- AU-3: Content of Audit Records - Comprehensive logging with timestamps and context
- AU-4: Audit Storage Capacity - Log file management and storage
- AU-6: Audit Review, Analysis, and Reporting - Error analysis and reporting
- AU-8: Time Stamps - Timestamp generation for all logged events
- SI-11: Error Handling - Systematic error handling and user notification
handle_exception
Centralized function to handle exceptions. Logs the error to both file and console, and displays a message to the user.Parameters
The exception that was caught and needs to be handled
A user-friendly message to display in the Streamlit UI. Should not contain sensitive information.
Returns
This function does not return a value. It logs the error and displays a message to the user.
NIST Controls Implemented
- SI-11: Error Handling - Centralized exception management
- AU-3: Content of Audit Records - Complete exception context capture
- AU-6: Audit Review - Error logging for analysis
Example Usage
log_error
Logs the error details to both file and console with timestamp and traceback.Parameters
The main error message to log
Any additional context or information about the error
Returns
This function does not return a value. It writes to log files and console.
NIST Controls Implemented
- AU-3: Content of Audit Records - Complete error context and metadata
- AU-8: Time Stamps - Precise timestamp for each error event
- AU-6: Audit Review - Structured format for analysis
- SI-11: Error Handling - Comprehensive error capture and logging
Example Usage
display_error_to_user
Displays an error message to the user in the Streamlit UI.Parameters
The error message to display to the user. Should be user-friendly and not contain sensitive details.
Returns
This function does not return a value. It displays the error in the Streamlit interface.
NIST Controls Implemented
- SI-11: Error Handling - User-friendly error messages without sensitive details
- AU-6: Audit Review - User notification as part of error handling process
Example Usage
setup_logging
Set up logging configuration and create log directory if it doesn’t exist.Returns
This function does not return a value. It configures the logging system.
NIST Controls Implemented
- AU-3: Content of Audit Records - Structured logging format
- AU-4: Audit Storage Capacity - Log directory creation and management
- AU-8: Time Stamps - Timestamp format configuration
Example Usage
Error Handling Patterns
Pattern 1: Simple Exception Handling
Usehandle_exception() for straightforward error handling with user feedback:
Pattern 2: Detailed Error Logging
Uselog_error() when you need to log errors with additional context:
Pattern 3: User-Only Error Display
Usedisplay_error_to_user() for validation errors that don’t need full logging:
Configuration
Log Directory
logs/ directory with the filename error.log. The directory is created automatically if it doesn’t exist.