Skip to content

Add fallback exception message#20780

Open
WarLikeLaux wants to merge 6 commits intoyiisoft:masterfrom
WarLikeLaux:add-fallback-exception-message
Open

Add fallback exception message#20780
WarLikeLaux wants to merge 6 commits intoyiisoft:masterfrom
WarLikeLaux:add-fallback-exception-message

Conversation

@WarLikeLaux
Copy link
Contributor

@WarLikeLaux WarLikeLaux commented Mar 4, 2026

Q A
Is bugfix?
New feature? ✔️
Breaks BC?
Fixed issues

What does this PR do?

Adds a public ErrorHandler::$fallbackExceptionMessage property to customize the error message shown to end users when YII_DEBUG is false and an exception occurs during error handling.

Previously, changing this message required overriding the entire handleFallbackExceptionMessage() method. Now it can be set via config - as a string or a callable:

'errorHandler' => [
    'fallbackExceptionMessage' => 'Service temporarily unavailable.',
],
'errorHandler' => [
    'fallbackExceptionMessage' => function ($exception, $previousException) {
        return 'Error: ' . $exception->getMessage();
    },
],

Alternative approach to #20681, which used a protected method. A public property is more consistent with existing ErrorHandler options like $discardExistingOutput and $silentExitOnException. Callable support adds flexibility without subclassing.

Includes 3 unit tests for the default value, string config and callable config. handleFallbackExceptionMessage() itself calls exit(1), so full integration testing is not practical, but the property path is covered.

@codecov
Copy link

codecov bot commented Mar 4, 2026

Codecov Report

❌ Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.13%. Comparing base (37b6e7b) to head (f0badce).
✅ 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   #20780      +/-   ##
============================================
- Coverage     80.13%   80.13%   -0.01%     
- Complexity    11533    11534       +1     
============================================
  Files           374      374              
  Lines         30206    30208       +2     
============================================
  Hits          24207    24207              
- Misses         5999     6001       +2     

☔ View full report in Codecov by Sentry.
📢 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.

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.

1 participant