Skip to content

Added method "fallbackExceptionMessage" to customize fallback exception message - #20681

Merged
terabytesoftw merged 3 commits into
yiisoft:masterfrom
ZhandosKz:error_handler_improvements
Oct 10, 2026
Merged

terabytesoftw merged 3 commits into
yiisoft:masterfrom
ZhandosKz:error_handler_improvements

Conversation

@ZhandosKz

Copy link
Copy Markdown
Contributor
Q A
Is bugfix? ❌
New feature? ✔️
Breaks BC? ❌

Added the ability to customize the critical error message for the handleFallbackExceptionMessage method.
Previously, customizing this message required completely overriding the handleFallbackExceptionMessage
method. This PR introduces the ability to customize the error text by overriding just one method:
fallbackExceptionMessage

@codecov

codecov Bot commented Nov 10, 2025 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.89%. Comparing base (2259153) to head (3e3c1fb).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
framework/base/ErrorHandler.php 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             master   #20681   +/-   ##
=========================================
  Coverage     81.89%   81.89%           
- Complexity    11556    11557    +1     
=========================================
  Files           374      374           
  Lines         30301    30303    +2     
=========================================
+ Hits          24815    24818    +3     
+ Misses         5486     5485    -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@samdark samdark left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks alright to me. Please add a line for changelog.

Comment thread framework/base/ErrorHandler.php Resolved
@coderabbitai

coderabbitai Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI (base), Organization UI (inherited)
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 5e4867e2-fd70-4ebd-a692-99255b458f67

📥 Commits

Reviewing files that changed from the base of the PR and between 617b649 and 3e3c1fb.


📒 Files selected for processing (2)
  • framework/CHANGELOG.md
  • framework/base/ErrorHandler.php

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📜 Recent review details
⏰ Context from checks skipped due to timeout. (75)
  • GitHub Check: MSSQL tests with coverage / PHP 7.4-mssql-2019-latest
  • GitHub Check: MSSQL tests with coverage / PHP 8.5-mssql-2019-latest
  • GitHub Check: MSSQL tests / PHP 8.4-mssql-2022-latest
  • GitHub Check: MySQL tests with coverage / PHP 7.4-mysql-5.7
  • GitHub Check: MSSQL tests with coverage / PHP 8.5-mssql-2022-latest
  • GitHub Check: MSSQL tests with coverage / PHP 7.4-mssql-2022-latest
  • GitHub Check: MySQL tests with coverage / PHP 7.4-mysql-latest
  • GitHub Check: MySQL tests / PHP 8.4-mysql-latest
  • GitHub Check: MySQL tests with coverage / PHP 8.5-mysql-latest
  • GitHub Check: MSSQL tests / PHP 8.1-mssql-2022-latest
  • GitHub Check: MSSQL tests / PHP 8.2-mssql-2022-latest
  • GitHub Check: MSSQL tests / PHP 8.3-mssql-2022-latest
  • GitHub Check: MySQL tests / PHP 8.0-mysql-latest
  • GitHub Check: PostgreSQL tests with coverage / PHP 7.4-pgsql-10
  • GitHub Check: MySQL tests / PHP 8.2-mysql-latest
  • GitHub Check: MySQL tests with coverage / PHP 8.5-mysql-5.7
  • GitHub Check: PostgreSQL tests with coverage / PHP 8.5-pgsql-14
  • GitHub Check: MariaDB tests / PHP 8.3-mysql-latest
  • GitHub Check: MySQL tests / PHP 8.1-mysql-latest
  • GitHub Check: PostgreSQL tests with coverage / PHP 7.4-pgsql-14
  • GitHub Check: PostgreSQL tests with coverage / PHP 7.4-pgsql-12
  • GitHub Check: PostgreSQL tests with coverage / PHP 7.4-pgsql-16
  • GitHub Check: PostgreSQL tests with coverage / PHP 7.4-pgsql-11
  • GitHub Check: MariaDB tests / PHP 8.4-mysql-latest
  • GitHub Check: MSSQL tests / PHP 8.0-mssql-2022-latest
  • GitHub Check: PostgreSQL tests / PHP 8.0-pgsql-latest
  • GitHub Check: PostgreSQL tests with coverage / PHP 8.5-pgsql-17
  • GitHub Check: PostgreSQL tests with coverage / PHP 8.5-pgsql-11
  • GitHub Check: PostgreSQL tests / PHP 8.4-pgsql-latest
  • GitHub Check: PostgreSQL tests with coverage / PHP 7.4-pgsql-13
  • GitHub Check: PostgreSQL tests with coverage / PHP 8.5-pgsql-15
  • GitHub Check: MariaDB tests / PHP 8.1-mysql-latest
  • GitHub Check: PostgreSQL tests with coverage / PHP 8.5-pgsql-16
  • GitHub Check: MariaDB tests / PHP 8.0-mysql-latest
  • GitHub Check: MariaDB tests with coverage / PHP 8.5-mysql-10.4
  • GitHub Check: PostgreSQL tests with coverage / PHP 8.5-pgsql-12
  • GitHub Check: PostgreSQL tests with coverage / PHP 8.5-pgsql-13
  • GitHub Check: MySQL tests / PHP 8.3-mysql-latest
  • GitHub Check: PostgreSQL tests with coverage / PHP 7.4-pgsql-17
  • GitHub Check: PostgreSQL tests with coverage / PHP 7.4-pgsql-15
  • GitHub Check: PostgreSQL tests / PHP 8.2-pgsql-latest
  • GitHub Check: PostgreSQL tests / PHP 8.3-pgsql-latest
  • GitHub Check: MariaDB tests with coverage / PHP 7.4-mysql-10.4
  • GitHub Check: PostgreSQL tests with coverage / PHP 8.5-pgsql-latest
  • GitHub Check: MariaDB tests with coverage / PHP 8.5-mysql-latest
  • GitHub Check: PostgreSQL tests with coverage / PHP 8.5-pgsql-10
  • GitHub Check: PostgreSQL tests with coverage / PHP 7.4-pgsql-latest
  • GitHub Check: MariaDB tests / PHP 8.2-mysql-latest
  • GitHub Check: PostgreSQL tests / PHP 8.1-pgsql-latest
  • GitHub Check: MariaDB tests with coverage / PHP 7.4-mysql-latest
  • GitHub Check: php-cs-fixer / PHP 7.4-ubuntu-latest
  • GitHub Check: SQLite tests / PHP 8.0-ubuntu-22.04
  • GitHub Check: SQLite tests / PHP 8.2-ubuntu-22.04
  • GitHub Check: SQLite tests / PHP 8.4-ubuntu-22.04
  • GitHub Check: SQLite tests with coverage / PHP 8.5-windows-latest
  • GitHub Check: SQLite tests with coverage / PHP 7.4-ubuntu-22.04
  • GitHub Check: rector / PHP 8.5-ubuntu-latest
  • GitHub Check: SQLite tests with coverage / PHP 7.4-windows-latest
  • GitHub Check: phpstan-7x / PHP 7.4-ubuntu-latest
  • GitHub Check: Oracle tests with coverage / PHP 8.5-oracle-slim-faststart
  • GitHub Check: Oracle tests with coverage / PHP 7.4-oracle-slim-faststart
  • GitHub Check: phpstan / PHP 8.5-ubuntu-latest
  • GitHub Check: PHP 8.2
  • GitHub Check: PHP 8.3
  • GitHub Check: PHP 8.2 Windows
  • GitHub Check: PHP 8.4
  • GitHub Check: PHP 7.4 Windows
  • GitHub Check: PHP 8 Windows
  • GitHub Check: PHP 8.1 Windows
  • GitHub Check: PHP 8.5 Windows
  • GitHub Check: PHP 8.3 Windows
  • GitHub Check: PHP 8.4 Windows
  • GitHub Check: PHP 8.1
  • GitHub Check: PHP 7.4
  • GitHub Check: PHP 8

🧰 Additional context used
🪛 ast-grep (0.45.3)
framework/base/ErrorHandler.php

[warning] 191-191: Avoid side effects in a file that defines symbols
Context: echo $this->fallbackExceptionMessage($exception, $previousException);
Note: [CWE-710] Improper Adherence to Coding Standards.

(no-side-effect)


🪛 PHPMD (2.15.0)
framework/base/ErrorHandler.php

[warning] 28-454: The class ErrorHandler has 12 public methods. Consider refactoring ErrorHandler to keep number of public methods under 10. (undefined)

(TooManyPublicMethods)


[warning] 28-454: The class ErrorHandler has an overall complexity of 55 which is very high. The configured complexity threshold is 50. (undefined)

(ExcessiveClassComplexity)


[error] 28-454: The property $_memoryReserve is not named in camelCase. (undefined)

(CamelCasePropertyName)


[error] 28-454: The property $_hhvmException is not named in camelCase. (undefined)

(CamelCasePropertyName)


[error] 28-454: The property $_registered is not named in camelCase. (undefined)

(CamelCasePropertyName)


[error] 28-454: The property $_workingDirectory is not named in camelCase. (undefined)

(CamelCasePropertyName)


[error] 28-454: The class ErrorHandler has a coupling between objects value of 13. Consider to reduce the number of dependencies under 13. (undefined)

(CouplingBetweenObjects)


[error] 177-198: handleFallbackExceptionMessage accesses the super-global variable $_SERVER. (undefined)

(Superglobals)


[error] 190-192: The method handleFallbackExceptionMessage uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. (undefined)

(ElseExpression)


[warning] 211-211: Avoid unused parameters such as '$exception'. (undefined)

(UnusedFormalParameter)


[warning] 211-211: Avoid unused parameters such as '$previousException'. (undefined)

(UnusedFormalParameter)


🔇 Additional comments (2)
framework/base/ErrorHandler.php (1)

191-191: LGTM!

Also applies to: 200-211


framework/CHANGELOG.md (1)

45-45: LGTM!



📝 Summary

Summary by CodeRabbit

  • New Features
    • The message shown for fallback errors when debug details are hidden can now be customized. By default, it remains a generic internal-server-error message.

Walkthrough

The non-debug fallback exception path now displays the result of fallbackExceptionMessage($exception, $previousException). The protected method returns the generic internal-server-error message by default.

Changes

Fallback exception message

Layer / File(s) Summary
Define and use fallback message
framework/base/ErrorHandler.php, framework/CHANGELOG.md
The non-debug fallback path calls fallbackExceptionMessage($exception, $previousException). The protected method returns the generic message by default. The changelog records this customization.

Priority: ⬇️ Low

Change: Feature

Merge Risk: ⚪ Minimal · up to 3e3c1

The default fallback response remains generic, and no merge-blocking issue is established.

Pre-merge checks | Passed 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check Passed The title clearly identifies the main change: adding fallbackExceptionMessage to customize the fallback exception message.
Description check Passed The description accurately explains the new feature, its purpose, and its backward-compatibility impact.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 1 files. (1 skipped: 1 …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.

✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR

🧪 Generate unit tests (beta)
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit checks the error trail,
A calmer message takes the rail.
When debug sleeps, the method speaks,
The default stays for quiet weeks.
I nibble greens and hop away!

Comment @coderabbitai help to get the list of available commands.

@terabytesoftw
terabytesoftw merged commit 9e1b7b0 into yiisoft:master Oct 10, 2026
82 of 84 checks passed
@terabytesoftw

Copy link
Copy Markdown
Member

Thks 👍

@terabytesoftw terabytesoftw added this to the 2.0.56 milestone Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants