ForgeErrorHandler Module

Overview

ForgeErrorHandler is an automatic error handling module that works out of the box to catch and handle all exceptions and errors in your application. Once installed, it requires no manual setup or integration - it automatically intercepts all errors and provides detailed error information for debugging.

Features

The error handler provides comprehensive error tracking and debugging capabilities automatically:

  • Automatic Error Catching: Catches all PHP errors and exceptions without any manual configuration
  • Syntax Highlighting: Code snippets are displayed with syntax highlighting for better readability
  • Stack Trace Analysis: Detailed stack traces with file and line information
  • Context Display: Shows the code context around the error location
  • Error Classification: Automatically categorizes errors by type and severity
  • Request Information: Includes HTTP request details when applicable
  • Environment Data: Displays relevant environment variables and configurations
  • Error Logging: Automatically logs errors to the configured log file

Configuration

The error handler has a simple configuration file located at config/forge_error_handler.php:

// config/forge_error_handler.php
return [
    'debugMode' => $_ENV['FORGE_APP_DEBUG'] === 'true',
    'logPath' => BASE_PATH . '/storage/logs/errors.log'
];

debugMode: Controls whether detailed error information is displayed. Set to true in development for detailed error pages, false in production for generic error messages.

logPath: Specifies the path where error logs will be stored. Defaults to storage/logs/errors.log.

Testing the Error Handler

You can test the error handler by throwing an exception anywhere in your code:

// Example: Testing the error handler
public function testErrorHandler()
{
    throw new Exception('Test exception to verify error handler');
}

// Or trigger a PHP error
trigger_error('Test error message', E_USER_ERROR);

When an error occurs, the error handler will automatically:

  • Display a detailed error page in debug mode
  • Log the error to the configured log file
  • Show a generic error page in production