Followup #2999721: [META] Deprecate the legacy include files before Drupal 9
Problem/Motivation
There is already an existing utility Error class. So lets keep things together.
Deprecate legacy errors.inc file functions. Just get rid of errors.inc file in drupal:10.0.x.
Proposed resolution
Convert all error handler related functions to the methods in the Error class.
That will help to work on the next step of modernizing Drupal error handler in #1722694: Fixed Kernel::init() overrides Drupal's error handling configuration without carrying out of legacy errors.inc file loading BC layer in Drupal 10.0.0.
Remaining tasks
Deprecate functionsReplace usages in the codeAdd legacy tests
User interface changes
-
API changes
- new methods in \Drupal\Core\Utility\Error class
- deprecated error handler related functions
Data model changes
-
Release notes snippet
-
| Comment | File | Size | Author |
|---|---|---|---|
| #113 | 3000229-113.patch | 69.8 KB | ajaypratapsingh |
| #105 | 3000229-105.patch | 68.77 KB | voleger |
Issue fork drupal-3000229
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
volegerTo do:
Comment #3
volegerAdded CR https://www.drupal.org/node/3009162
Comment #4
volegerAdded @trigger_error messages.
Comment #5
volegerAdded deprecation messages.
Patch looks ready for review.
Comment #6
volegerComment #7
volegerThis is not a meta issue now
Comment #9
volegerAs it touches error handling processes add Needs framework manager review tag to the issue.
Comment #10
catchGiving this a more specific title.
Comment #11
volegerRerolled after #2947291: Missing argument 5 for _drupal_error_handler()
Marked converted methods from _drupal_*functions as internal.
Comment #12
goodboy commentedSet default values to $severity_msg and $severity_level at begin of the function.
More compact (https://wiki.php.net/rfc/isset_ternary)
Comment #13
voleger#12.1 Thanks, updated
#12.2 It is not BC. See https://3v4l.org/MqbAq . isset_ternary (??) available > php7.0. But Drupal 8 supports > php5.5.9. So I can't change that.
Comment #14
borisson_I think this looks great, but I can't do the required framework manager review.
Comment #15
andypostLooks good, some minor feedback
It also needs deprecation test
no reason in intermediate variable - just return array
I'd better add `defined('DRUPAL_TEST_IN_CHILD_SITE')` to condition
that makes me think about this function still should be loaded to make this class selfcontained, also a lot of services accesses via \Drupal::
Use ?: instead of isset()
Comment #16
voleger#15.1 - fixed
#15.2 - fixed
#15.3 - included bootstrap.inc file
#15.4 - this will trigger notice level error. kept as it is.
Added tests.
Comment #18
volegerReplaced DRUPAL_ROOT by the service call
Comment #20
volegerFixed failing tests, reverted replacements of DRUPAL_ROOT.
Comment #21
volegerComment #23
volegeradded _drupal_exception_handler and _drupal_exception_handler_additional
Comment #24
volegerComment #25
volegerComment #26
volegerComment #27
volegerComment #28
dawehnerI don't think unit tests should load include files, would it be able to make this a kernel test
Comment #29
volegerAddressed #28
Also updated deprecation messagess regarding new CS rules.
Comment #30
aaronmchaleAny chance we could do this instead? #1722694: Fixed Kernel::init() overrides Drupal's error handling configuration
Also see my comment on the issue about how to make Symfony's Error Handling work with our level of granularity: #23
I think there would be significant benefits to doing this, one that comes to mind is a much nicer debugging experience, really I cannot stress enough how nice it is compared to Drupal's.
Comment #31
volegerHere added shutdown handler and deprecated ERROR_REPORTNIG_* constants.
Comment #32
berdirI'm not sure about moving this to the Error class.
It's not specific to errors, it's shutdown stuff that should happen always (including errors) so I feel like that should be its own thing, what is the reason for moving it to Error?
Comment #33
volegerI created followup for the shutdown handler - #3053773: Move shutdown functions into the shutdown handler class.
Reverted changes related to shutdown functions.
So here two interdiffs:
31-33 - revert shutdown functions changes
29-33 - ERROR_REPORTING_* constants deprecations
Comment #34
volegerNeeds reroll
Comment #35
martin107 commentedI am rerolling
Comment #36
martin107 commentedNot the easiest of rerolls
function from error.inc copied and mutated slight as they move into Error.php
Here are the code changes as I see them. Lets hope I have dealt with everything cleanly.
A)
The logic for this conditional has been updated in core recently.
B)
The try catch pattern in Error:exceptionHandler() has been simplified
Comment #38
volegerA) This update from Drupal causes the bug during LegacyTest API calls. So here the fix.
B) Happy to see dropped support of php5
Comment #39
volegerAnd complete fixes related to CS issues of deprecation messages.
Comment #40
martin107 commentedthank you -- I had half finished my corrections but Mondays are always a little busy.
In term of review this looks good to me. - The Legacy test did need adjustment.
Comment #41
volegerFound 1 missed replacement (wondering why the test not failed previously)
Added
errors.incfile deprecation message.Still needs review
Comment #43
volegermissed include call
Comment #44
volegerComment #46
volegerRemoved file @trigger_error call and added TODO for errors.inc include file remove
Comment #48
volegerDatabase fail. back to needs review
Comment #49
volegerComment #50
berdirI think so far we didn't explicitly deprecate a file as a while, this is slightly different as it is loaded conditionally but I still think that's covered with deprecating all the functions in it, and when updating that, if someone calls it directly, they can remove that then.
I think getLevels() would make more sense here, that also matches \Drupal\Core\Logger\RfcLogLevel::getLevels
Error::getLevel() doesn't seem every explicit in what it returns, what about getCurrentLevel(), that's also better separated from levels/getLevels then.
same here, I think methods should generally be verbNoun() or just verb(), header isn't a verb :)
could be addHeader() or something more verbose, some arguments use emit, so could be emitHeader()? but add is probably easier to found. Also not 100% sure about it being public. Most functions are prefixed with _, but so is _drupal_error_handler_real() and that does need to be called. Still, this function is currently only called from within the other error functions and could be a candidate to make protected?
We had a similar case in file_unmanaged_prepare(), initial patches hat it as public with a @todo to make it internal, but in the end, we just made it protected and kept the old function in place, easier to clean-up/remove then, it's not that much code after all.
And in combination with it being a protected helper, I kinda like emitHeader() or emitAssertionHeader()
like above, not sure that's necessary, other functions like database.inc and entity.inc didn't get that todo either. If we keep it, then it should be @todo :)
do we still need to wrap it now that it is a static method and not a function? Sometimes unit tests use such wrappers to mock different return values,
Either we could deprecate this method too or we should update the docblock.
are these arguments optional for some kind of PHP BC? Maybe we can simplify it by making them required? $context is also deprecated in PHP 7.2, we could could possibly not define that at all, since we aren't using it anyway.
the include is necessary? log() uses it too and I guess we implicitly rely on this being called first?
that's pretty ugly :) (the ignore warnings part)
Comment #51
volegerAddressed #50
#50.1 - let's remove the message
#50.2 - updated
#50.3 - updated
#50.4 - updated
#50.5 - just removed todo message. anyway there would be deprecated functions removal process, so calls to the empty script files also wuld be removed during that process.
#50.6 - replaced usages with direct call of
Error::isDisplayable()#50.7 - totaly agree as this is PHP BC. updated
#50.8 - removed
#50.9 - introduced 2 different patches with and without silencing. Lets see wich will not break the legacy test.
Comment #53
voleger#50.8 - the tests from #51 comment shows that lines are necessary. Added reference to #3052703: Deprecate drupal_installation_attempted().
#50.9 - removal of '@' looks good.
Comment #55
volegerLooks like we have a blocker #3052703: Deprecate drupal_installation_attempted()
Comment #56
volegerPrepared two patches:
3000229-56-DO-NOT-COMMIT-INCLUDES-3052703-5.patch- specially to test both patches applied on the current codebase. If it passes - the following patch has to be ready after #3052703: Deprecate drupal_installation_attempted() goes in.3000229-56.patch- patch rerolled over core codebase that applied changes from #3052703, so it ready for test after unpostponing this issue.Comment #57
voleger#3052703: Deprecate drupal_installation_attempted() landed
Let's run tests for
3000229-56.patchComment #58
volegerTests passed with
3000229-56.patch. See #56. It's ready for review.Comment #59
andypostIt looks ready to go
this method is protected so it needs follow-up to remove
IIRC we do not remove wrappers on conversion
yay!
this is not set @internal (as others) and it looks right
Comment #60
andypostRe-roll #56 cos applies with offset
Comment #61
andypostComment #62
voleger#60 looks good for me +1 for rtbc
Comment #63
larowlanso my question here is are we going far enough.
We're replacing one procedural function with a static, and not gaining things like dependency injection, e.g. the ::log method uses the container singleton
is this a first-step towards a proper error handler ala
\Symfony\Component\HttpKernel\EventListener\DebugHandlersListener?Do we have a larger plan here?
Because if we do, we might find we have to do this again in 9.x.
Comment #65
volegerYes, definitely #1722694: Fixed Kernel::init() overrides Drupal's error handling configuration is the best candidate for that.
And yes - we will convert Error static class into the proper handler in Drupal 9.
The scope of this issue is to get rid of
errors.incfile right now, and use autloadable static methods. That will make easier conversion from static methods to Symfony handler without worry about handling includes file that we actually trying to drop here before Drupal 9.Comment #67
volegerUnrelated test fail. Back to RTBC
Comment #68
andypostFix CS and needs review for 9.0
Comment #69
volegerHere the drupal:9.0.x patch
Comment #70
volegerAdded info for the following steps.
Comment #71
volegerSo we have the patches for drupal:8.8.x and drupal:8.9.x in #68
and a patch in #69 for drupal:9.0.x
Comment #72
volegerRerolled #68 patch against latest 9.0.x
Comment #73
volegerComment #74
daffie commentedThe patch needs a reroll. I did a very quick review:
Are the parameters $filename and $line optional or not?
Comment #75
martin107 commentedI will do the reroll
Comment #76
martin107 commentedreroll now .. I will work on 74 next
Comment #78
martin107 commentedA) Fixed bug... not sure If I have everything.
B) $filename, $line, $context those parameters are no longer needed/used.. so deleted.
Comment #80
martin107 commentedopps
Comment #81
martin107 commentedbetter
Comment #83
martin107 commenteda simple fix.
Comment #84
volegerLooks better now.
But what about CS issues?
Can we address them in the followup or in this issue?
Comment #85
martin107 commentedI am not sure that I follow
Do you mean coding standard issues ... The test results do not show any additional CS issues.
I think this issue is complete... well ready for review.
Comment #86
daffie commentedPatch looks good. Some remarks:
This function is being deprecated. There is however no deprecation message test.
The same as with _drupal_exception_handler.
Same as with _drupal_exception_handler.
This can we rewritten to:
[$severity_msg, $severity_level] = $types[$error_level];This change is not correct. Now we are only testing if the constant exists. We should also be testing that the value is TRUE.
Same as previous point.
Can we remove this empty line.
Comment #87
martin107 commented@daffie thanks for the detailed review.
I am on it.
Comment #88
voleger#86.1, #86.2 and #86.3: first point is that they are internal functions, so they haven't to be used by the contribs or custom module. Also that's why we marked them as @internal in new API. Second point is if we will trigger error in the error handler we will go into recursion. If I understand correctly the error handlers are not so easy to test.
#86.4, #86.5, #86.6,
#86.7 and #86.8 are addressed
Comment #89
volegerComment #90
longwaveWhy does this still call
_drupal_error_handler_real()? Can't it callError::handler()directly now, like the deprecation message suggests?Unsure if this is bikeshedding but we often use verbs as method names so this could just be
handle()?Similarly this would read better as
handleException()?And this could be
handleAdditionalException()?Why not
usethis class and then only call Error::log() here?Comment #91
volegerAddressed #90
Comment #92
longwaveThanks, looks great now - let's see what framework managers think.
Comment #93
alexpottSome thoughts:
Comment #94
volegerAddressed CS issue and #93.1
Comment #95
himanshu_sindhwani commentedCorrecting the failing test case in #94.
Comment #97
himanshu_sindhwani commentedUploaded the wrong patch in #95. Here is a complete fix.
interdiff:
Comment #98
himanshu_sindhwani commentedComment #99
daffie commentedThe fix for comment #93.1 is good.
The other 2 points #93.2 and #93.3 are still open.
Comment #100
volegerAdded legacy tests for
_drupal_exception_handlerand_drupal_exception_handler_realRemoved overridden usage of
FinalExceptionSubscriber::isErrorDisplayable()inTestDefaultExceptionSubscriberclassComment #101
longwaveAll review points were addressed but #100 no longer applies.
Comment #102
volegerRerolled
Comment #103
volegerIf all points addressed can we move it to RTBC?
Comment #104
longwave#102 needs reroll again, but I think this can be set to RTBC after rerolling.
Comment #105
volegerHere is rerolled patch.
Comment #106
alexpottIs not addressed. The Error class is still full of \Drupal calls. With this issue it feels like we trading a compromised API (from an OO design perspective) for the same API. I.e. we moved everything around but not much has really changed. We still struggle to unit test our error handling because it is coupled to the globals like \Drupal::root() or whatever.
I think this issue should start with an API design that is fit for purpose. Doing this issue makes it harder to do this until Drupal 10 because it gives us 2 static APIs to support rather than the single one we have today. This is likely to be hard to do because the error system is very tangly.
I think this patch can deprecate drupal_error_levels() and the constants but the rest of it needs work.
Comment #107
aaronmchaleFollowing on from #106 I feel like it would make a lot more sense to focused on #1722694: Fixed Kernel::init() overrides Drupal's error handling configuration instead, as we could just strip out all of the custom error handling that Drupal has and just adapt Symfony's to work for our needs. Thereby reducing overhead and likely solving the issues Alex mentioned in #106.
In comment #1722694-23: Fixed Kernel::init() overrides Drupal's error handling configuration I noted how we could address the issue of Symfony's TRUE/FALSE debugging options to fit our more granular needs:
Comment #108
andypostRelated issue changed signature
Comment #113
ajaypratapsingh commentedRerolled patch against drupal 9.5.x
Comment #114
volegerNeeds reroll
Comment #115
longwaveNeeds more than just reroll, #106 needs addressing which is a change in direction.
Comment #117
anybodyComment #118
andypostComment #119
mstrelan commentedAdding #3526515: Use get_error_handler() in php 8.5 and deprecate Error::currentErrorHandler as related.
Comment #121
voleger