Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handleException() adds own trace when calling handleError() #1374

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions htdocs/class/logger/xoopslogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public function enableRendering()
*/
public function microtime()
{
/** @var array $now */
$now = explode(' ', microtime());

return (float)$now[0] + (float)$now[1];
Expand Down Expand Up @@ -213,24 +214,27 @@ public function addDeprecated($msg)
* @param string $errstr
* @param string $errfile
* @param string $errline
* @param array|null $trace
*/
public function handleError($errno, $errstr, $errfile, $errline)
public function handleError($errno, $errstr, $errfile, $errline,$trace=null)
{
if ($this->activated && ($errno & error_reporting())) {
// NOTE: we only store relative pathnames
$this->errors[] = compact('errno', 'errstr', 'errfile', 'errline');
}
if ($errno == E_USER_ERROR) {
$trace = true;
$includeTrace = true;
if (substr($errstr, 0, '8') === 'notrace:') {
$trace = false;
$includeTrace = false;
$errstr = substr($errstr, 8);
}
echo sprintf(_XOOPS_FATAL_MESSAGE, $errstr);
if ($trace && function_exists('debug_backtrace')) {
if ($includeTrace) {
echo "<div style='color:#f0f0f0;background-color:#f0f0f0;'>" . _XOOPS_FATAL_BACKTRACE . ':<br>';
$trace = debug_backtrace();
array_shift($trace);
if ($trace === null && function_exists('debug_backtrace')) {
$trace = \debug_backtrace();
array_shift($trace); // Remove the first element, which is this function itself
}
foreach ($trace as $step) {
if (isset($step['file'])) {
echo $this->sanitizePath($step['file']);
Expand All @@ -254,7 +258,7 @@ public function handleException($e)
{
if ($this->isThrowable($e)) {
$msg = get_class($e) . ': ' . $this->sanitizePath($this->sanitizeDbMessage($e->getMessage()));
$this->handleError(E_USER_ERROR, $msg, $e->getFile(), $e->getLine());
$this->handleError(E_USER_ERROR, $msg, $e->getFile(), $e->getLine(), $e->getTrace());
}
}

Expand Down Expand Up @@ -374,7 +378,7 @@ public function dumpTime($name = 'XOOPS', $unset = false)
* @param string $errStr
* @param string $errFile
* @param string $errLine
* @param integer $errNo
* @param int $errNo
* @return void
*/
public function triggerError($errkey = 0, $errStr = '', $errFile = '', $errLine = '', $errNo = 0)
Expand Down