ErrorPage: display debug info in separate box

This commit is contained in:
2025-02-26 15:33:18 +01:00
parent 13cbe08219
commit 041b56ff8c
3 changed files with 74 additions and 34 deletions

View File

@@ -3,7 +3,7 @@
* ErrorHandler.php
* Contains key class ErrorHandler.
*
* Kabuki CMS (C) 2013-2016, Aaron van Geffen
* Kabuki CMS (C) 2013-2025, Aaron van Geffen
*****************************************************************************/
class ErrorHandler
@@ -47,10 +47,8 @@ class ErrorHandler
// Log the error in the database.
self::logError($error_message, $debug_info, $file, $line);
// Are we considering this fatal? Then display and exit.
// !!! TODO: should we consider warnings fatal?
if (true) // DEBUG || (!DEBUG && $error_level === E_WARNING || $error_level === E_USER_WARNING))
self::display($file . ' (' . $line . ')<br>' . $error_message, $debug_info);
// Display error and exit.
self::display($error_message, $file, $line, $debug_info);
// If it wasn't a fatal error, well...
self::$handling_error = false;
@@ -118,7 +116,7 @@ class ErrorHandler
}
// Logs an error into the database.
private static function logError($error_message = '', $debug_info = '', $file = '', $line = 0)
public static function logError($error_message = '', $debug_info = '', $file = '', $line = 0)
{
if (!ErrorLog::log([
'message' => $error_message,
@@ -130,7 +128,7 @@ class ErrorHandler
'request_uri' => isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '',
]))
{
header('HTTP/1.1 503 Service Temporarily Unavailable');
http_response_code(503);
echo '<h2>An Error Occurred</h2><p>Our software could not connect to the database. We apologise for any inconvenience and ask you to check back later.</p>';
exit;
}
@@ -138,7 +136,7 @@ class ErrorHandler
return $error_message;
}
public static function display($message, $debug_info, $is_sensitive = true)
public static function display($message, $file, $line, $debug_info, $is_sensitive = true)
{
$is_admin = Registry::has('user') && Registry::get('user')->isAdmin();
@@ -167,7 +165,8 @@ class ErrorHandler
$is_admin = Registry::has('user') && Registry::get('user')->isAdmin();
if (DEBUG || $is_admin)
{
$page->adopt(new DummyBox('An error occurred!', '<p>' . $message . '</p><pre>' . $debug_info . '</pre>'));
$debug_info = sprintf("Trigger point:\n%s (L%d)\n\n%s", $file, $line, $debug_info);
$page->adopt(new ErrorPage('An error occurred!', $message, $debug_info));
// Let's provide the admin navigation despite it all!
if ($is_admin)
@@ -176,9 +175,9 @@ class ErrorHandler
}
}
elseif (!$is_sensitive)
$page->adopt(new DummyBox('An error occurred!', '<p>' . $message . '</p>'));
$page->adopt(new ErrorPage('An error occurred!', '<p>' . $message . '</p>'));
else
$page->adopt(new DummyBox('An error occurred!', '<p>Our apologies, an error occurred while we were processing your request. Please try again later, or contact us if the problem persists.</p>'));
$page->adopt(new ErrorPage('An error occurred!', 'Our apologies, an error occurred while we were processing your request. Please try again later, or contact us if the problem persists.'));
// If we got this far, make sure we're not showing stuff twice.
ob_end_clean();