Skip to content

Commit

Permalink
Merge pull request #9144 from kenjis/fix-inconsistency-in-detailed-er…
Browse files Browse the repository at this point in the history
…ror-reports

[4.6] fix: inconsistency in detailed error reporting
  • Loading branch information
kenjis authored Aug 30, 2024
2 parents 1938a7c + fd21659 commit 675c819
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
22 changes: 14 additions & 8 deletions system/Debug/ExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ public function handle(
);
}

// Handles non-HTML requests.
if (! str_contains($request->getHeaderLine('accept'), 'text/html')) {
$data = (ENVIRONMENT === 'development' || ENVIRONMENT === 'testing')
// If display_errors is enabled, shows the error details.
$data = $this->isDisplayErrorsEnabled()
? $this->collectVars($exception, $statusCode)
: '';

Expand Down Expand Up @@ -134,13 +136,8 @@ protected function determineView(
// Production environments should have a custom exception file.
$view = 'production.php';

if (
in_array(
strtolower(ini_get('display_errors')),
['1', 'true', 'on', 'yes'],
true
)
) {
if ($this->isDisplayErrorsEnabled()) {
// If display_errors is enabled, shows the error details.
$view = 'error_exception.php';
}

Expand All @@ -158,4 +155,13 @@ protected function determineView(

return $view;
}

private function isDisplayErrorsEnabled(): bool
{
return in_array(
strtolower(ini_get('display_errors')),
['1', 'true', 'on', 'yes'],
true
);
}
}
13 changes: 13 additions & 0 deletions user_guide_src/source/changelogs/v4.6.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@ Time::setTimestamp()
``Time::setTimestamp()`` behavior has been fixed.
See :ref:`Upgrading Guide <upgrade-460-time-set-timestamp>` for details.

Error Reporting to Non-HTML Requests
------------------------------------

In previous versions, when a request does not accept HTML, CodeIgniter showed
error details only in the ``development`` and ``testing`` environments.

But because it is not possible to display error details when using a custom
environment, this behavior has been fixed so that error details are displayed if
``display_errors`` in PHP ini setting is enabled.

With this fix, the error details are now displayed under the same conditions for
both HTML requests and non-HTML requests.

.. _v460-interface-changes:

Interface Changes
Expand Down
10 changes: 7 additions & 3 deletions user_guide_src/source/general/errors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ Configuration
Error Reporting
---------------

By default, CodeIgniter will display a detailed error report with all errors in the ``development`` and ``testing`` environments, and will not
display any errors in the ``production`` environment.
When ``display_errors`` in PHP ini setting is enabled, CodeIgniter will display
a detailed error report with all errors

So by default, CodeIgniter will display a detailed error report in the ``development``
and ``testing`` environments, and will not display any errors in the ``production``
environment.

.. image:: ../images/error.png

Expand Down Expand Up @@ -251,7 +255,7 @@ the **error_404.php** in the **app/Views/errors/cli** folder.
If there is no view file corresponding to the HTTP status code, **production.php**
or **error_exception.php** will be displayed.

.. note:: If ``display_errors`` is on in the PHP INI configuration,
.. note:: If ``display_errors`` is on in the PHP ini setting,
**error_exception.php** is selected and a detailed error report is displayed.

You should customize all of the error views in the **app/Views/errors/html** folder
Expand Down

0 comments on commit 675c819

Please sign in to comment.