Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.6] fix: inconsistency in detailed error reporting #9144

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading