From b6b7f6c66737c3bd495ed481b4b6800eac74ba4e Mon Sep 17 00:00:00 2001
From: Simon Rettberg
Date: Wed, 13 Jul 2016 11:06:38 +0200
Subject: [util] Made traceError output prettier by using HTML
---
inc/util.inc.php | 64 +++++++++++++++++++++++++++++++++++++++++++-------------
1 file changed, 49 insertions(+), 15 deletions(-)
(limited to 'inc/util.inc.php')
diff --git a/inc/util.inc.php b/inc/util.inc.php
index 1b29aa39..14621a5a 100644
--- a/inc/util.inc.php
+++ b/inc/util.inc.php
@@ -12,32 +12,38 @@ class Util
*/
public static function traceError($message)
{
- if (defined('API')) {
+ if (defined('API') && API) {
error_log('API ERROR: ' . $message);
}
Header('HTTP/1.1 500 Internal Server Error');
- Header('Content-Type: text/plain; charset=utf-8');
- echo "--------------------\nFlagrant system error:\n$message\n--------------------\n\n";
+ Header('Content-Type: text/html; charset=utf-8');
+ echo '
Fatal Error';
+ echo 'Flagrant System error
';
+ echo "Message
$message
";
+ if (strpos($message, 'Database') !== false) {
+ echo '';
+ }
+ echo "
";
if (defined('CONFIG_DEBUG') && CONFIG_DEBUG) {
global $SLX_ERRORS;
-/*
- 'errno' => $errno,
- 'errstr' => $errstr,
- 'errfile' => $errfile,
- 'errline' => $errline,
- */
if (!empty($SLX_ERRORS)) {
+ echo 'PHP Errors
';
foreach ($SLX_ERRORS as $error) {
- echo "{$error['errstr']} ({$error['errfile']}:{$error['errline']}\n";
+ echo htmlspecialchars("{$error['errstr']} ({$error['errfile']}:{$error['errline']}\n");
}
- echo "--------------------\n";
+ echo '
';
}
- debug_print_backtrace();
- echo "\n\nSome variables for your entertainment:\n";
- print_r($GLOBALS);
+ echo "Stack Trace
";
+ echo '', self::formatBacktrace(debug_backtrace()), '
';
+ echo "Globals
";
+ echo print_r($GLOBALS, true);
+ echo '
';
} else {
echo <<
________________________¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶________
____________________¶¶¶___________________¶¶¶¶_____
________________¶¶¶_________________________¶¶¶¶___
@@ -61,11 +67,39 @@ __¶¶¶________________________________¶¶____________
___¶¶¶____________________________¶¶_______________
____¶¶¶¶______________________¶¶¶__________________
_______¶¶¶¶¶_____________¶¶¶¶¶_____________________
+
SADFACE;
}
+ echo '';
exit(0);
}
+ public static function formatBacktrace($trace, $escape = true)
+ {
+ $output = '';
+ foreach ($trace as $idx => $line) {
+ $args = array();
+ foreach ($line['args'] as $arg) {
+ if (is_string($arg)) {
+ $arg = "'$arg'";
+ } elseif (is_object($arg)) {
+ $arg = 'instanceof ' . get_class($arg);
+ } elseif (is_array($arg)) {
+ $arg = 'Array(' . count($arg) . ')';
+ }
+ $args[] = '' . htmlspecialchars($arg) . '';
+ }
+ $frame = str_pad('#' . $idx, 3, ' ', STR_PAD_LEFT);
+ $function = htmlspecialchars($line['function']);
+ $args = implode(', ', $args);
+ $file = preg_replace('~(/[^/]+)$~', '$1', htmlspecialchars($line['file']));
+ // Add line
+ $output .= $frame . ' ' . $function . '('
+ . $args . ')' . ' @ ' . $file . ':' . $line['line'] . "\n";
+ }
+ return $output;
+ }
+
/**
* Redirects the user via a '302 Moved' header.
* An active session will be saved, any messages that haven't
--
cgit v1.2.3-55-g7522