diff options
author | Simon Rettberg | 2016-08-15 16:50:44 +0200 |
---|---|---|
committer | Simon Rettberg | 2016-08-15 16:50:44 +0200 |
commit | e40ee176b7a9142f61644745991cb22564392741 (patch) | |
tree | b228b798763457fbccf492b712658b81b291b22d | |
parent | [statistics] Fix list view and sorting (diff) | |
download | slx-admin-e40ee176b7a9142f61644745991cb22564392741.tar.gz slx-admin-e40ee176b7a9142f61644745991cb22564392741.tar.xz slx-admin-e40ee176b7a9142f61644745991cb22564392741.zip |
[util] traceError(): Don't output html junk if running via CLI
-rw-r--r-- | inc/util.inc.php | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/inc/util.inc.php b/inc/util.inc.php index 8ad3928a..bee07765 100644 --- a/inc/util.inc.php +++ b/inc/util.inc.php @@ -14,7 +14,11 @@ class Util { if (defined('API') && API) { error_log('API ERROR: ' . $message); - error_log(print_r(debug_backtrace(), true)); + error_log(self::formatBacktracePlain(debug_backtrace())); + } + if (php_sapi_name() === 'cli') { + // Don't spam HTML when invoked via cli, above error_log should have gone to stdout/stderr + exit(1); } Header('HTTP/1.1 500 Internal Server Error'); Header('Content-Type: text/html; charset=utf-8'); @@ -38,7 +42,7 @@ class Util echo '</pre>'; } echo "<h2>Stack Trace</h2>"; - echo '<pre>', self::formatBacktrace(debug_backtrace()), '</pre>'; + echo '<pre>', self::formatBacktraceHtml(debug_backtrace()), '</pre>'; echo "<h2>Globals</h2><pre>"; echo print_r($GLOBALS, true); echo '</pre>'; @@ -75,7 +79,7 @@ SADFACE; exit(0); } - public static function formatBacktrace($trace, $escape = true) + public static function formatBacktraceHtml($trace, $escape = true) { $output = ''; foreach ($trace as $idx => $line) { @@ -101,6 +105,30 @@ SADFACE; return $output; } + public static function formatBacktracePlain($trace) + { + $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[] = $arg; + } + $frame = str_pad('#' . $idx, 3, ' ', STR_PAD_LEFT); + $args = implode(', ', $args); + // Add line + $output .= "\n" . $frame . ' ' . $line['function'] . '(' + . $args . ')' . ' @ ' . $line['file'] . ':' . $line['line']; + } + return $output; + } + /** * Redirects the user via a '302 Moved' header. * An active session will be saved, any messages that haven't |