Skip to content

Commit 32f42e9

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into 4.5
Conflicts: system/Debug/Exceptions.php
2 parents 59fa588 + 8657525 commit 32f42e9

File tree

5 files changed

+75
-12
lines changed

5 files changed

+75
-12
lines changed

app/Views/errors/cli/error_exception.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,26 @@
33
use CodeIgniter\CLI\CLI;
44

55
// The main Exception
6-
CLI::newLine();
76
CLI::write('[' . get_class($exception) . ']', 'light_gray', 'red');
8-
CLI::newLine();
97
CLI::write($message);
10-
CLI::newLine();
118
CLI::write('at ' . CLI::color(clean_path($exception->getFile()) . ':' . $exception->getLine(), 'green'));
129
CLI::newLine();
1310

11+
$last = $exception;
12+
13+
while ($prevException = $last->getPrevious()) {
14+
$last = $prevException;
15+
16+
CLI::write(' Caused by:');
17+
CLI::write(' [' . get_class($prevException) . ']', 'red');
18+
CLI::write(' ' . $prevException->getMessage());
19+
CLI::write(' at ' . CLI::color(clean_path($prevException->getFile()) . ':' . $prevException->getLine(), 'green'));
20+
CLI::newLine();
21+
}
22+
1423
// The backtrace
1524
if (defined('SHOW_DEBUG_BACKTRACE') && SHOW_DEBUG_BACKTRACE) {
16-
$backtraces = $exception->getTrace();
25+
$backtraces = $last->getTrace();
1726

1827
if ($backtraces) {
1928
CLI::write('Backtrace:', 'green');

app/Views/errors/html/error_exception.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,29 @@
4444
<?php endif; ?>
4545
</div>
4646

47+
<div class="container">
48+
<?php
49+
$last = $exception;
50+
51+
while ($prevException = $last->getPrevious()) {
52+
$last = $prevException;
53+
?>
54+
55+
<pre>
56+
Caused by:
57+
<?= esc(get_class($prevException)), esc($prevException->getCode() ? ' #' . $prevException->getCode() : '') ?>
58+
59+
<?= nl2br(esc($prevException->getMessage())) ?>
60+
<a href="https://www.duckduckgo.com/?q=<?= urlencode(get_class($prevException) . ' ' . preg_replace('#\'.*\'|".*"#Us', '', $prevException->getMessage())) ?>"
61+
rel="noreferrer" target="_blank">search &rarr;</a>
62+
<?= esc(clean_path($prevException->getFile()) . ':' . $prevException->getLine()) ?>
63+
</pre>
64+
65+
<?php
66+
}
67+
?>
68+
</div>
69+
4770
<?php if (defined('SHOW_DEBUG_BACKTRACE') && SHOW_DEBUG_BACKTRACE) : ?>
4871
<div class="container">
4972

system/Debug/BaseExceptionHandler.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,14 @@ abstract public function handle(
6767
*/
6868
protected function collectVars(Throwable $exception, int $statusCode): array
6969
{
70-
$trace = $exception->getTrace();
70+
// Get the first exception.
71+
$firstException = $exception;
72+
73+
while ($prevException = $firstException->getPrevious()) {
74+
$firstException = $prevException;
75+
}
76+
77+
$trace = $firstException->getTrace();
7178

7279
if ($this->config->sensitiveDataInTrace !== []) {
7380
$trace = $this->maskSensitiveData($trace, $this->config->sensitiveDataInTrace);

system/Debug/Exceptions.php

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,22 +130,31 @@ public function exceptionHandler(Throwable $exception)
130130
$uri = $this->request->getPath() === '' ? '/' : $this->request->getPath();
131131
$routeInfo = '[Method: ' . $this->request->getMethod() . ', Route: ' . $uri . ']';
132132

133-
log_message('critical', "{message}\n{routeInfo}\nin {exFile} on line {exLine}.\n{trace}", [
133+
log_message('critical', get_class($exception) . ": {message}\n{routeInfo}\nin {exFile} on line {exLine}.\n{trace}", [
134134
'message' => $exception->getMessage(),
135135
'routeInfo' => $routeInfo,
136136
'exFile' => clean_path($exception->getFile()), // {file} refers to THIS file
137137
'exLine' => $exception->getLine(), // {line} refers to THIS line
138138
'trace' => self::renderBacktrace($exception->getTrace()),
139139
]);
140-
}
141140

142-
$this->response = Services::response();
141+
// Get the first exception.
142+
$last = $exception;
143143

144-
// Get the first exception.
145-
while ($prevException = $exception->getPrevious()) {
146-
$exception = $prevException;
144+
while ($prevException = $last->getPrevious()) {
145+
$last = $prevException;
146+
147+
log_message('critical', '[Caused by] ' . get_class($prevException) . ": {message}\nin {exFile} on line {exLine}.\n{trace}", [
148+
'message' => $prevException->getMessage(),
149+
'exFile' => clean_path($prevException->getFile()), // {file} refers to THIS file
150+
'exLine' => $prevException->getLine(), // {line} refers to THIS line
151+
'trace' => self::renderBacktrace($prevException->getTrace()),
152+
]);
153+
}
147154
}
148155

156+
$this->response = Services::response();
157+
149158
if (method_exists($this->config, 'handler')) {
150159
// Use new ExceptionHandler
151160
$handler = $this->config->handler($statusCode, $exception);
@@ -330,7 +339,14 @@ protected function render(Throwable $exception, int $statusCode)
330339
*/
331340
protected function collectVars(Throwable $exception, int $statusCode): array
332341
{
333-
$trace = $exception->getTrace();
342+
// Get the first exception.
343+
$firstException = $exception;
344+
345+
while ($prevException = $firstException->getPrevious()) {
346+
$firstException = $prevException;
347+
}
348+
349+
$trace = $firstException->getTrace();
334350

335351
if ($this->config->sensitiveDataInTrace !== []) {
336352
$trace = $this->maskSensitiveData($trace, $this->config->sensitiveDataInTrace);

user_guide_src/source/installation/upgrade_444.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ Please refer to the upgrade instructions corresponding to your installation meth
1616
Mandatory File Changes
1717
**********************
1818

19+
Error Files
20+
===========
21+
22+
Update the following files to show correct error messages:
23+
24+
- app/Views/errors/cli/error_exception.php
25+
- app/Views/errors/html/error_exception.php
26+
1927
****************
2028
Breaking Changes
2129
****************

0 commit comments

Comments
 (0)