|
|
@@ -67,23 +67,48 @@ class ConsoleExceptionRenderer implements ExceptionRendererInterface
|
|
|
*/
|
|
|
public function render(): ResponseInterface|string
|
|
|
{
|
|
|
+ $exceptions = [$this->error];
|
|
|
+ $previous = $this->error->getPrevious();
|
|
|
+ while ($previous !== null) {
|
|
|
+ $exceptions[] = $previous;
|
|
|
+ $previous = $previous->getPrevious();
|
|
|
+ }
|
|
|
$out = [];
|
|
|
- $out[] = sprintf(
|
|
|
- '<error>[%s] %s</error> in %s on line %s',
|
|
|
- get_class($this->error),
|
|
|
- $this->error->getMessage(),
|
|
|
- $this->error->getFile(),
|
|
|
- $this->error->getLine()
|
|
|
- );
|
|
|
+ foreach ($exceptions as $i => $error) {
|
|
|
+ $out = array_merge($out, $this->renderException($error, $i));
|
|
|
+ }
|
|
|
+
|
|
|
+ return join("\n", $out);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Render an individual exception
|
|
|
+ *
|
|
|
+ * @param \Throwable $exception The exception to render.
|
|
|
+ * @param int $index Exception index in the chain
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ protected function renderException(Throwable $exception, int $index): array
|
|
|
+ {
|
|
|
+ $out = [
|
|
|
+ sprintf(
|
|
|
+ '<error>%s[%s] %s</error> in %s on line %s',
|
|
|
+ $index > 0 ? 'Caused by ' : '',
|
|
|
+ get_class($exception),
|
|
|
+ $exception->getMessage(),
|
|
|
+ $exception->getFile(),
|
|
|
+ $exception->getLine()
|
|
|
+ ),
|
|
|
+ ];
|
|
|
|
|
|
$debug = Configure::read('debug');
|
|
|
- if ($debug && $this->error instanceof CakeException) {
|
|
|
- $attributes = $this->error->getAttributes();
|
|
|
+ if ($debug && $exception instanceof CakeException) {
|
|
|
+ $attributes = $exception->getAttributes();
|
|
|
if ($attributes) {
|
|
|
$out[] = '';
|
|
|
$out[] = '<info>Exception Attributes</info>';
|
|
|
$out[] = '';
|
|
|
- $out[] = var_export($this->error->getAttributes(), true);
|
|
|
+ $out[] = var_export($exception->getAttributes(), true);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -91,11 +116,11 @@ class ConsoleExceptionRenderer implements ExceptionRendererInterface
|
|
|
$out[] = '';
|
|
|
$out[] = '<info>Stack Trace:</info>';
|
|
|
$out[] = '';
|
|
|
- $out[] = $this->error->getTraceAsString();
|
|
|
+ $out[] = $exception->getTraceAsString();
|
|
|
$out[] = '';
|
|
|
}
|
|
|
|
|
|
- return join("\n", $out);
|
|
|
+ return $out;
|
|
|
}
|
|
|
|
|
|
/**
|