Skip to content

Commit 64cd95c

Browse files
committed
fix: the stack trace displayed when Exception handler runs out of memory is useless
1 parent ccab9b7 commit 64cd95c

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

system/Debug/Exceptions.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ class Exceptions
6868
*/
6969
protected $response;
7070

71+
private ?Throwable $exceptionCaughtByExceptionHandler = null;
72+
7173
/**
7274
* @param CLIRequest|IncomingRequest $request
7375
*/
@@ -113,6 +115,8 @@ public function initialize()
113115
*/
114116
public function exceptionHandler(Throwable $exception)
115117
{
118+
$this->exceptionCaughtByExceptionHandler = $exception;
119+
116120
[$statusCode, $exitCode] = $this->determineCodes($exception);
117121

118122
if ($this->config->log === true && ! in_array($statusCode, $this->config->ignoreCodes, true)) {
@@ -191,6 +195,13 @@ public function shutdownHandler()
191195

192196
['type' => $type, 'message' => $message, 'file' => $file, 'line' => $line] = $error;
193197

198+
if ($this->exceptionCaughtByExceptionHandler) {
199+
$message .= "\n【Previous Exception】\n"
200+
. get_class($this->exceptionCaughtByExceptionHandler) . "\n"
201+
. $this->exceptionCaughtByExceptionHandler->getMessage() . "\n"
202+
. $this->exceptionCaughtByExceptionHandler->getTraceAsString();
203+
}
204+
194205
if (in_array($type, [E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_PARSE], true)) {
195206
$this->exceptionHandler(new ErrorException($message, 0, $type, $file, $line));
196207
}

0 commit comments

Comments
 (0)