Added ability to debug ajax_die() calls (#1023)

This commit is contained in:
Roman Kelesidis 2023-11-03 17:33:57 +07:00 committed by GitHub
commit f2fe7d2e0c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 6 deletions

View file

@ -147,6 +147,13 @@ class Ajax
$this->response['error_code'] = $error_code; $this->response['error_code'] = $error_code;
$this->response['error_msg'] = strip_tags($error_msg); $this->response['error_msg'] = strip_tags($error_msg);
// Get caller info
if (!empty($_COOKIE['explain'])) {
$ajax_debug = 'ajax die: ' . $this->debug_find_source();
$this->response['error_msg'] .= "\n\n" . $ajax_debug;
$this->response['console_log'] = $ajax_debug;
}
$this->send(); $this->send();
} }
@ -272,6 +279,33 @@ class Ajax
} }
} }
/**
* Find caller source
*
* @param string $mode
* @return mixed|string
*/
function debug_find_source(string $mode = 'all'): mixed
{
if (empty($_COOKIE['explain'])) {
return 'src disabled';
}
foreach (debug_backtrace() as $trace) {
if (!empty($trace['file']) && $trace['file'] !== __FILE__) {
switch ($mode) {
case 'file':
return $trace['file'];
case 'line':
return $trace['line'];
case 'all':
default:
return hide_bb_path($trace['file']) . '(' . $trace['line'] . ')';
}
}
}
return 'src not found';
}
/** /**
* Edit user profile actions * Edit user profile actions
* *

View file

@ -91,10 +91,9 @@ class Common
* Find caller source * Find caller source
* *
* @param string $mode * @param string $mode
*
* @return string * @return string
*/ */
public function debug_find_source(string $mode = ''): string public function debug_find_source(string $mode = 'all'): string
{ {
if (!SQL_PREPEND_SRC_COMM) { if (!SQL_PREPEND_SRC_COMM) {
return 'src disabled'; return 'src disabled';
@ -106,6 +105,7 @@ class Common
return $trace['file']; return $trace['file'];
case 'line': case 'line':
return $trace['line']; return $trace['line'];
case 'all':
default: default:
return hide_bb_path($trace['file']) . '(' . $trace['line'] . ')'; return hide_bb_path($trace['file']) . '(' . $trace['line'] . ')';
} }

View file

@ -165,10 +165,9 @@ class Common
* Find caller source * Find caller source
* *
* @param string $mode * @param string $mode
*
* @return string * @return string
*/ */
public function debug_find_source(string $mode = ''): string public function debug_find_source(string $mode = 'all'): string
{ {
if (!SQL_PREPEND_SRC_COMM) { if (!SQL_PREPEND_SRC_COMM) {
return 'src disabled'; return 'src disabled';
@ -180,6 +179,7 @@ class Common
return $trace['file']; return $trace['file'];
case 'line': case 'line':
return $trace['line']; return $trace['line'];
case 'all':
default: default:
return hide_bb_path($trace['file']) . '(' . $trace['line'] . ')'; return hide_bb_path($trace['file']) . '(' . $trace['line'] . ')';
} }

View file

@ -845,10 +845,9 @@ class SqlDb
* Find caller source * Find caller source
* *
* @param string $mode * @param string $mode
*
* @return string * @return string
*/ */
public function debug_find_source(string $mode = ''): string public function debug_find_source(string $mode = 'all'): string
{ {
if (!SQL_PREPEND_SRC_COMM) { if (!SQL_PREPEND_SRC_COMM) {
return 'src disabled'; return 'src disabled';
@ -860,6 +859,7 @@ class SqlDb
return $trace['file']; return $trace['file'];
case 'line': case 'line':
return $trace['line']; return $trace['line'];
case 'all':
default: default:
return hide_bb_path($trace['file']) . '(' . $trace['line'] . ')'; return hide_bb_path($trace['file']) . '(' . $trace['line'] . ')';
} }

View file

@ -343,6 +343,7 @@ Ajax.prototype = {
} }
} else if (response.error_code) { } else if (response.error_code) {
ajax.showErrorMsg(response.error_msg); ajax.showErrorMsg(response.error_msg);
console.log(response.console_log);
$('.loading-1').removeClass('loading-1').html('error'); $('.loading-1').removeClass('loading-1').html('error');
} else { } else {
ajax.callback[action](response); ajax.callback[action](response);