diff --git a/src/Ajax.php b/src/Ajax.php index a051d70ff..d85be8730 100644 --- a/src/Ajax.php +++ b/src/Ajax.php @@ -147,6 +147,13 @@ class Ajax $this->response['error_code'] = $error_code; $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(); } @@ -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 * diff --git a/src/Legacy/Cache/Common.php b/src/Legacy/Cache/Common.php index 41acaa66d..59d7049ee 100644 --- a/src/Legacy/Cache/Common.php +++ b/src/Legacy/Cache/Common.php @@ -91,10 +91,9 @@ class Common * Find caller source * * @param string $mode - * * @return string */ - public function debug_find_source(string $mode = ''): string + public function debug_find_source(string $mode = 'all'): string { if (!SQL_PREPEND_SRC_COMM) { return 'src disabled'; @@ -106,6 +105,7 @@ class Common return $trace['file']; case 'line': return $trace['line']; + case 'all': default: return hide_bb_path($trace['file']) . '(' . $trace['line'] . ')'; } diff --git a/src/Legacy/Datastore/Common.php b/src/Legacy/Datastore/Common.php index 9cea545bc..f67e2bdfa 100644 --- a/src/Legacy/Datastore/Common.php +++ b/src/Legacy/Datastore/Common.php @@ -165,10 +165,9 @@ class Common * Find caller source * * @param string $mode - * * @return string */ - public function debug_find_source(string $mode = ''): string + public function debug_find_source(string $mode = 'all'): string { if (!SQL_PREPEND_SRC_COMM) { return 'src disabled'; @@ -180,6 +179,7 @@ class Common return $trace['file']; case 'line': return $trace['line']; + case 'all': default: return hide_bb_path($trace['file']) . '(' . $trace['line'] . ')'; } diff --git a/src/Legacy/SqlDb.php b/src/Legacy/SqlDb.php index 46b92a864..a485a0f15 100644 --- a/src/Legacy/SqlDb.php +++ b/src/Legacy/SqlDb.php @@ -845,10 +845,9 @@ class SqlDb * Find caller source * * @param string $mode - * * @return string */ - public function debug_find_source(string $mode = ''): string + public function debug_find_source(string $mode = 'all'): string { if (!SQL_PREPEND_SRC_COMM) { return 'src disabled'; @@ -860,6 +859,7 @@ class SqlDb return $trace['file']; case 'line': return $trace['line']; + case 'all': default: return hide_bb_path($trace['file']) . '(' . $trace['line'] . ')'; } diff --git a/styles/js/main.js b/styles/js/main.js index 2957c327d..10a2f4265 100644 --- a/styles/js/main.js +++ b/styles/js/main.js @@ -343,6 +343,7 @@ Ajax.prototype = { } } else if (response.error_code) { ajax.showErrorMsg(response.error_msg); + console.log(response.console_log); $('.loading-1').removeClass('loading-1').html('error'); } else { ajax.callback[action](response);