Skip to content

Commit 675c819

Browse files
authored
Merge pull request #9144 from kenjis/fix-inconsistency-in-detailed-error-reports
[4.6] fix: inconsistency in detailed error reporting
2 parents 1938a7c + fd21659 commit 675c819

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

system/Debug/ExceptionHandler.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@ public function handle(
7575
);
7676
}
7777

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

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

137-
if (
138-
in_array(
139-
strtolower(ini_get('display_errors')),
140-
['1', 'true', 'on', 'yes'],
141-
true
142-
)
143-
) {
139+
if ($this->isDisplayErrorsEnabled()) {
140+
// If display_errors is enabled, shows the error details.
144141
$view = 'error_exception.php';
145142
}
146143

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

159156
return $view;
160157
}
158+
159+
private function isDisplayErrorsEnabled(): bool
160+
{
161+
return in_array(
162+
strtolower(ini_get('display_errors')),
163+
['1', 'true', 'on', 'yes'],
164+
true
165+
);
166+
}
161167
}

user_guide_src/source/changelogs/v4.6.0.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,19 @@ Time::setTimestamp()
7777
``Time::setTimestamp()`` behavior has been fixed.
7878
See :ref:`Upgrading Guide <upgrade-460-time-set-timestamp>` for details.
7979

80+
Error Reporting to Non-HTML Requests
81+
------------------------------------
82+
83+
In previous versions, when a request does not accept HTML, CodeIgniter showed
84+
error details only in the ``development`` and ``testing`` environments.
85+
86+
But because it is not possible to display error details when using a custom
87+
environment, this behavior has been fixed so that error details are displayed if
88+
``display_errors`` in PHP ini setting is enabled.
89+
90+
With this fix, the error details are now displayed under the same conditions for
91+
both HTML requests and non-HTML requests.
92+
8093
.. _v460-interface-changes:
8194

8295
Interface Changes

user_guide_src/source/general/errors.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,12 @@ Configuration
5757
Error Reporting
5858
---------------
5959

60-
By default, CodeIgniter will display a detailed error report with all errors in the ``development`` and ``testing`` environments, and will not
61-
display any errors in the ``production`` environment.
60+
When ``display_errors`` in PHP ini setting is enabled, CodeIgniter will display
61+
a detailed error report with all errors
62+
63+
So by default, CodeIgniter will display a detailed error report in the ``development``
64+
and ``testing`` environments, and will not display any errors in the ``production``
65+
environment.
6266

6367
.. image:: ../images/error.png
6468

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

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

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

0 commit comments

Comments
 (0)