I am working on a site that has errors, and debug is turned on in the configuration. But all I see is the image below with a bare error and no context. How can I get the usual debug information?
1 Answer
It means that the template you're using does not render the stack trace in its error layout. To render the stack trace, use Joomla\CMS\Document\ErrorDocument::renderBacktrace()
method. The stack trace should be rendered only when debug is enabled to prevent leaking sensitive data. So at a bare minimum this code can be used inside error.php
:
<?php if ($this->debug) : ?>
<?= $this->renderBacktrace() ?>
<?php endif; ?>
The exception may contain previous exceptions. In which case you should also render them. Something like this should work:
<?php if ($this->debug) : ?>
<?= $this->renderBacktrace() ?>
<?php // Loop over exceptions ?>
<?php while ($error = $this->_error->getPrevious()) : ?>
<?php // Set the previous exception ?>
<?php $this->setError($error) ?>
<p><?= htmlspecialchars($error->getMessage(), ENT_QUOTES, 'UTF-8') ?></p>
<?= $this->renderBacktrace() ?>
<?php endwhile ?>
<?php // Restore the original exception ?>
<?php $this->setError($this->error) ?>
<?php endif ?>
-
Thanks very much. There are a number of files called error.php but I pinned it down to the one that is in a layout belong to the default template. I couldn't implement your solution as the layout appeared not to be inheriting from the Joomla class - renderBacktrace was an unknown method. But I expanded the error message using methods on the exception to get the failing file and line number which was enough to find the problems. Commented Sep 9, 2023 at 14:34