Skip to content

Commit

Permalink
Also show nested exception where available
Browse files Browse the repository at this point in the history
  • Loading branch information
flack committed Jul 10, 2024
1 parent 2850f89 commit f269499
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/errors.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,10 @@ private function _send_email(string $msg, array $config, string $servername)
}
}

public function get_function_stack()
public function get_function_stack(?Throwable $error = null)
{
$stack = $this->error->getTrace();
$error = $error ?? $this->error;
$stack = $error->getTrace();

$stacktrace = [];
foreach ($stack as $number => $frame) {
Expand Down
6 changes: 5 additions & 1 deletion lib/midcom/style/midcom_error.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@
<?php
$stacktrace = $this->data['error_handler']->get_function_stack();
if (!empty($stacktrace)) {
echo "<pre>Stacktrace:\n" . implode("\n", $stacktrace) . "</pre>\n";
echo "<pre>Stacktrace:\n" . implode("\n", $stacktrace);
if ($prev = $this->data['error_exception']->getPrevious()) {
echo "\n\nCaused by:\n" . implode("\n", $this->data['error_handler']->get_function_stack($prev));
}
echo "</pre>\n";
}
?>
</body>
Expand Down
4 changes: 4 additions & 0 deletions themes/OpenPsa2/style/midcom_error.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
if (!empty($stacktrace)) {
echo '<h3>Stacktrace:</h3>';
echo "<pre>" . implode("\n", $stacktrace) . "</pre>\n";
if ($prev = $this->data['error_exception']->getPrevious()) {
echo '<h3>Caused by:</h3>';
echo "<pre>" . implode("\n", $this->data['error_handler']->get_function_stack($prev)) . "</pre>\n";
}
}
?>
</div>
Expand Down

0 comments on commit f269499

Please sign in to comment.