diff --git a/formwork/src/Controllers/ErrorsController.php b/formwork/src/Controllers/ErrorsController.php index 3fba8fe21..9febe8d62 100644 --- a/formwork/src/Controllers/ErrorsController.php +++ b/formwork/src/Controllers/ErrorsController.php @@ -24,7 +24,7 @@ public function error(ResponseStatus $responseStatus = ResponseStatus::InternalS if ($this->config->getBool('system.debug.enabled') || $this->request->isLocalhost()) { $data['throwable'] = $throwable; - $data['stackTrace'] = $throwable !== null ? $this->getTrace($throwable) : []; + $data['traceResolver'] = $this->getTrace(...); } if ($this->request->isXmlHttpRequest()) { @@ -80,14 +80,19 @@ public function forbidden(): Response */ private function logThrowable(Throwable $throwable): void { - error_log(sprintf( - "Uncaught %s: %s in %s:%s\nStack trace:\n%s\n", - $throwable::class, - $throwable->getMessage(), - $throwable->getFile(), - $throwable->getLine(), - $throwable->getTraceAsString() - )); + // Log the throwable like the native PHP exception handler does + $messages = []; + do { + array_unshift($messages, sprintf( + "%s: %s in %s:%s\nStack trace:\n%s\n", + $throwable::class, + $throwable->getMessage(), + $throwable->getFile(), + $throwable->getLine(), + $throwable->getTraceAsString() + )); + } while ($throwable = $throwable->getPrevious()); + error_log('Uncaught ' . implode("\nNext ", $messages)); } /** @@ -95,8 +100,12 @@ private function logThrowable(Throwable $throwable): void * * @return array}> */ - private function getTrace(Throwable $throwable): array + private function getTrace(?Throwable $throwable): array { + if ($throwable === null) { + return []; + } + $trace = $throwable->getTrace(); $file = $throwable->getFile(); diff --git a/formwork/src/Debug/CodeDumper.php b/formwork/src/Debug/CodeDumper.php index 3ef7337c3..f0a325d53 100644 --- a/formwork/src/Debug/CodeDumper.php +++ b/formwork/src/Debug/CodeDumper.php @@ -36,7 +36,7 @@ final class CodeDumper } .color-scheme-dark .__formwork-code { - background-color: #333; + background-color: #333638; color: #f0f0f0; } diff --git a/formwork/src/Panel/Controllers/ErrorsController.php b/formwork/src/Panel/Controllers/ErrorsController.php index 6861b2f9b..6116758bc 100644 --- a/formwork/src/Panel/Controllers/ErrorsController.php +++ b/formwork/src/Panel/Controllers/ErrorsController.php @@ -70,7 +70,7 @@ private function makeErrorResponse(ResponseStatus $responseStatus, string $name, if ($this->config->getBool('system.debug.enabled') || $this->request->isLocalhost()) { $data['throwable'] = $throwable; - $data['stackTrace'] = $throwable !== null ? $this->getTrace($throwable) : []; + $data['traceResolver'] = $this->getTrace(...); } if ($this->request->isXmlHttpRequest()) { @@ -103,14 +103,19 @@ private function makeErrorResponse(ResponseStatus $responseStatus, string $name, */ private function logThrowable(Throwable $throwable): void { - error_log(sprintf( - "Uncaught %s: %s in %s:%s\nStack trace:\n%s\n", - $throwable::class, - $throwable->getMessage(), - $throwable->getFile(), - $throwable->getLine(), - $throwable->getTraceAsString() - )); + // Log the throwable like the native PHP exception handler does + $messages = []; + do { + array_unshift($messages, sprintf( + "%s: %s in %s:%s\nStack trace:\n%s\n", + $throwable::class, + $throwable->getMessage(), + $throwable->getFile(), + $throwable->getLine(), + $throwable->getTraceAsString() + )); + } while ($throwable = $throwable->getPrevious()); + error_log('Uncaught ' . implode("\nNext ", $messages)); } /** @@ -118,8 +123,12 @@ private function logThrowable(Throwable $throwable): void * * @return array}> */ - private function getTrace(Throwable $throwable): array + private function getTrace(?Throwable $throwable): array { + if ($throwable === null) { + return []; + } + $trace = $throwable->getTrace(); $file = $throwable->getFile(); diff --git a/formwork/views/errors/partials/debug.php b/formwork/views/errors/partials/debug.php index f1c252c70..ed1ff5c34 100644 --- a/formwork/views/errors/partials/debug.php +++ b/formwork/views/errors/partials/debug.php @@ -1,11 +1,16 @@ -
-

Uncaught : escape($throwable->getMessage()) ?>

- $frame) : ?> - -
attr(['open' => $i === 0]) ?>> - $1', $frame['file']) ?>: - config()->getInt('system.debug.contextLines', 5)) ?> -
- - + +
+

Uncaught : escape($throwable->getMessage()) ?>

+ $frame) : ?> + +
attr(['open' => $i === 0]) ?>> + $1', $frame['file']) ?>: + config()->getInt('system.debug.contextLines', 5)) ?> +
+ + +
+ getPrevious() ?> + +
diff --git a/formwork/views/errors/partials/header.php b/formwork/views/errors/partials/header.php index 0b803876a..48896bb9a 100644 --- a/formwork/views/errors/partials/header.php +++ b/formwork/views/errors/partials/header.php @@ -90,7 +90,7 @@ } .error-debug-details { - margin: 0 auto 4rem; + margin: 0 auto 2rem; max-width: 87.5rem; text-align: left; border-radius: 4px; @@ -133,4 +133,4 @@

escape($message ?? 'Internal Server Error') ?> -

\ No newline at end of file + diff --git a/panel/src/scss/components/_errors.scss b/panel/src/scss/components/_errors.scss index a4cac2fb8..c10d961f7 100644 --- a/panel/src/scss/components/_errors.scss +++ b/panel/src/scss/components/_errors.scss @@ -48,9 +48,13 @@ max-width: 87.5rem; padding: 1.5rem 2rem; border-radius: var(--border-radius); - margin: 0 auto 4rem; + margin: 0 auto 2rem; background-color: var(--color-base-900); text-align: left; + + .color-scheme-dark & { + background-color: var(--color-base-800); + } } .error-debug-details h3 { diff --git a/panel/views/errors/error.php b/panel/views/errors/error.php index 1407056ce..a5920073f 100644 --- a/panel/views/errors/error.php +++ b/panel/views/errors/error.php @@ -25,19 +25,22 @@ escape($action['label']) ?>
- +
-
-

Uncaught : escape($throwable->getMessage()) ?>

- $frame) : ?> - -
attr(['open' => $i === 0]) ?>> - $1', $frame['file']) ?>: - config()->getInt('system.debug.contextLines', 5)) ?> -
- - -
+ +
+

Uncaught : escape($throwable->getMessage()) ?>

+ $frame) : ?> + +
attr(['open' => $i === 0]) ?>> + $1', $frame['file']) ?>: + config()->getInt('system.debug.contextLines', 5)) ?> +
+ + +
+ getPrevious() ?> +
@@ -45,4 +48,4 @@ insert('@panel._scripts') ?> - \ No newline at end of file +