From eae6010e05c6d2027973fdeb72a98bf1f38c605b Mon Sep 17 00:00:00 2001 From: michalsn Date: Mon, 9 Dec 2024 07:51:36 +0100 Subject: [PATCH 1/3] fix: exceptions for non-HTML responses should rely on display_errors setting --- system/Debug/ExceptionHandler.php | 6 +++++- user_guide_src/source/changelogs/v4.5.6.rst | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/system/Debug/ExceptionHandler.php b/system/Debug/ExceptionHandler.php index d6f97b76a32b..41b67a626f37 100644 --- a/system/Debug/ExceptionHandler.php +++ b/system/Debug/ExceptionHandler.php @@ -76,7 +76,11 @@ public function handle( } if (! str_contains($request->getHeaderLine('accept'), 'text/html')) { - $data = (ENVIRONMENT === 'development' || ENVIRONMENT === 'testing') + $data = in_array( + strtolower(ini_get('display_errors')), + ['1', 'true', 'on', 'yes'], + true + ) ? $this->collectVars($exception, $statusCode) : ''; diff --git a/user_guide_src/source/changelogs/v4.5.6.rst b/user_guide_src/source/changelogs/v4.5.6.rst index 9490e62e4e80..f59885387a3f 100644 --- a/user_guide_src/source/changelogs/v4.5.6.rst +++ b/user_guide_src/source/changelogs/v4.5.6.rst @@ -42,6 +42,7 @@ Bugs Fixed - **Validation:** Fixed a bug where complex language strings were not properly handled. - **CURLRequest:** Added support for handling proxy responses using HTTP versions other than 1.1. - **Database:** Fixed a bug that caused ``Postgre\Connection::reconnect()`` method to throw an error when the connection had not yet been established. +- **Exception:** Fixed a bug where exceptions for non-HTML responses were not relying on the PHP ``display_errors`` setting. See the repo's `CHANGELOG.md `_ From ededc90c0fda245ae4737fe6ada8d92a8497ee1e Mon Sep 17 00:00:00 2001 From: michalsn Date: Mon, 9 Dec 2024 08:43:09 +0100 Subject: [PATCH 2/3] remove code duplication --- system/Debug/ExceptionHandler.php | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/system/Debug/ExceptionHandler.php b/system/Debug/ExceptionHandler.php index 41b67a626f37..8d495402a23d 100644 --- a/system/Debug/ExceptionHandler.php +++ b/system/Debug/ExceptionHandler.php @@ -76,11 +76,7 @@ public function handle( } if (! str_contains($request->getHeaderLine('accept'), 'text/html')) { - $data = in_array( - strtolower(ini_get('display_errors')), - ['1', 'true', 'on', 'yes'], - true - ) + $data = $this->isDisplayErrorsEnabled() ? $this->collectVars($exception, $statusCode) : ''; @@ -138,13 +134,7 @@ 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()) { $view = 'error_exception.php'; } @@ -162,4 +152,16 @@ protected function determineView( return $view; } + + /** + * Whether the PHP display_errors setting is enabled. + */ + private function isDisplayErrorsEnabled(): bool + { + return in_array( + strtolower(ini_get('display_errors')), + ['1', 'true', 'on', 'yes'], + true + ); + } } From 5dab62d55107ee50d98a483e0712a757eacb47ea Mon Sep 17 00:00:00 2001 From: michalsn Date: Mon, 9 Dec 2024 13:35:55 +0100 Subject: [PATCH 3/3] move isDisplayErrorsEnabled() to BaseExceptionHandler class for reuse --- system/Debug/BaseExceptionHandler.php | 12 ++++++++++++ system/Debug/ExceptionHandler.php | 12 ------------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/system/Debug/BaseExceptionHandler.php b/system/Debug/BaseExceptionHandler.php index 4305265d2d2c..cc2200b7a440 100644 --- a/system/Debug/BaseExceptionHandler.php +++ b/system/Debug/BaseExceptionHandler.php @@ -268,4 +268,16 @@ protected function render(Throwable $exception, int $statusCode, $viewFile = nul return ob_get_clean(); })(); } + + /** + * Whether the PHP display_errors setting is enabled. + */ + protected function isDisplayErrorsEnabled(): bool + { + return in_array( + strtolower(ini_get('display_errors')), + ['1', 'true', 'on', 'yes'], + true + ); + } } diff --git a/system/Debug/ExceptionHandler.php b/system/Debug/ExceptionHandler.php index 8d495402a23d..415226108f62 100644 --- a/system/Debug/ExceptionHandler.php +++ b/system/Debug/ExceptionHandler.php @@ -152,16 +152,4 @@ protected function determineView( return $view; } - - /** - * Whether the PHP display_errors setting is enabled. - */ - private function isDisplayErrorsEnabled(): bool - { - return in_array( - strtolower(ini_get('display_errors')), - ['1', 'true', 'on', 'yes'], - true - ); - } }