diff options
author | Florian Pritz <bluewind@xinu.at> | 2014-12-06 21:19:08 +0100 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2014-12-06 21:19:08 +0100 |
commit | 38db82116dfd543a08a553ae75112e6992a7718d (patch) | |
tree | 26fdff80825ac13d2a2c375a2033791c7547f2b0 /index.php | |
parent | cdb983cfa7da19294ab82993aa073f0116026e9a (diff) |
Improve backtraces
PHP's default functions truncate longer argument values so backtrace
will not be as helpful as they could be. This code tries to mimic PHP's
way of printing traces except it prints full arguments.
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'index.php')
-rw-r--r-- | index.php | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -219,18 +219,29 @@ function _actual_exception_handler($e) $GLOBALS["is_error_page"] = true; $heading = "Internal Server Error"; $message = "<p>An unhandled error occured.</p>\n"; + + $backtrace = ""; + $i = 0; + foreach ($e->getTrace() as $key => $frame) { + $backtrace .= sprintf("#%d %s(%d): %s(%s)\n", + $i++, isset($frame["file"]) ? $frame["file"] : "[internal function]", + isset($frame["line"]) ? $frame["line"] : "", $frame["function"], implode(", ", array_map( + function ($e) { return var_export($e, true); }, $frame["args"]))); + } + if ($display_errors) { $message .= '<div>'; $message .= '<b>Fatal error</b>: Uncaught exception '.get_class($e).'<br>'; $message .= '<b>Message</b>: '.$e->getMessage().'<br>'; - $message .= '<pre>'.(str_replace(FCPATH, "./", $e->getTraceAsString())).'</pre>'; + $message .= '<pre>'.(str_replace(FCPATH, "./", $backtrace)).'</pre>'; $message .= 'thrown in <b>'.$e->getFile().'</b> on line <b>'.$e->getLine().'</b><br>'; $message .= '</div>'; } else { $message .="<p>More information can be found in syslog or by enabling display_errors.</p>"; } - error_log($e); + $heading = sprintf("Exception '%s' with message '%s' in %s:%d", get_class($e), $e->getMessage(), $e->getFile(), $e->getLine()); + error_log($heading."\n".$backtrace); $message = "$message"; include APPPATH."/errors/error_general.php"; |