Problem/Motivation
Currently DrupalKernel::handleException() currently always calls out to drupal_handle_exception ... which makes it hard in case you have your own exception handler.
With #2509898: Additional uncaught exception thrown while handling exception after service changes we started to no longer try to render things in a nice way,
as let's be honest, relying on a working system when you know a system is broken already, is simply wrong.
For development purposes though there are MUCH better exception/error libraries out there.
filp.github.io/whoops/ is one of them http://booboo.thephpleague.com/ is another one
Another problem is that for some sites they maybe want to present a different screen.
Proposed resolution
To be discussed, probably
Remaining tasks
User interface changes
API changes
Data model changes
Beta phase evaluation
| Issue category | Bug, because its Drupal should support custom exception handlers |
|---|---|
| Issue priority | Major, because it allows for a much better DX |
| Disruption | No disruption as no change in functionality, just a bugfix that you cananot use your own exception handler. |
| Comment | File | Size | Author |
|---|---|---|---|
| #25 | interdiff.txt | 1.91 KB | znerol |
| #22 | make_it_possible_to_use-2521852-22.patch | 5.92 KB | znerol |
| #22 | interdiff.txt | 2.17 KB | znerol |
| #17 | make_it_possible_to_use-2521852-17.patch | 5.54 KB | znerol |
| #12 | make_it_possible_to_use-2521852-12.patch | 5.9 KB | znerol |
Comments
Comment #1
dawehnerComment #2
dawehnerLet's see
Comment #3
znerol commentedAs of PHP 5.5 you may pass
NULLtoset_exception_handlerand still get back the current handler.Comment #4
znerol commentedHow about just rethrow unless there is a
HttpException? This would be analogous to whatHttpKerneldoes if no subscriber handled the exception.Comment #5
Crell commentedCurious: Why? What's the use case here? That should get added to the issue summary to justify a Major.
Comment #6
dawehnerExplained things a bit more in the issue summary
IN general this "help" message doesn't help you that much anyway, and even more important with #2509898: Additional uncaught exception thrown while handling exception after service changes this is dead code now,
as the additional catch is never fired.
Comment #7
znerol commentedTest only patch equals interdiff.
Comment #8
znerol commentedComment #10
dawehnerAll this is now dead code, so we can just continue to throw, which will then let the exception we catched by maybe the custom exception handler or another wrapper around DrupalKernel (you never know)
Comment #12
znerol commentedRebase succeeded with auto-merging. Only some context lines changed.
Comment #13
dawehnerBack to RTBC
Comment #17
znerol commentedReroll.
Comment #18
aspilicious commentedBeter DX is normal, not major. But I don't say no to this patch.
Comment #19
dawehner@aspilicious
This issue isn't tagged with it :P
I think this is quite a WTF that Drupal dictates you that. Also cleaning up DrupalKernel should be a favour of everyone :)
Comment #20
dawehnerStill RTBC
Comment #21
neclimdulNit: We should document @throws in the docblock now.
Is this ordered this way to ensure output buffering? If there isn't a test specifically for that we might want to document it here so it isn't accidentally removed later to "correct" the order.
Comment #22
znerol commentedUh, well, that only worked because
output_bufferingis turned on on most PHP installations (including test bots).Comment #23
dawehnerThat interdiff is confusing :)
Comment #24
neclimdulYeah, but the patch looks great! :)
Comment #25
znerol commentedHuh!? I do not even have a working copy of
coder_snifferon my disk. Maybe that's a sign :)Interesting detail: interdiff_14927.txt and interdiff_14928.txt are the same files.
Comment #26
alexpottAre we sure we want to remove this? How are we sure this code is dead?
Comment #27
znerol commentedThe only way to get there is when an exception is thrown while handling an exception in
_drupal_exception_handler()or_drupal_log_error()(i.e. if the exception handler itself is broken). This was a quite common case before #2509898: Additional uncaught exception thrown while handling exception after service changes, but is now fixed.In my opinion there is no meaningful message we can display when the exception handler breaks. With the patch we trade that misleading message for improved DX.
Comment #28
alexpottI'm not totally sold on the idea that
That said I don't think we should get in the way as much as we do and we definitely should let our exception handler do it's job without calling function marked as private directly from DrupalKernel.
For me the only remaining question is should we be catching container errors that might be fixed by a rebuilding and adding info to the message? In the issue summary of #2509898: Additional uncaught exception thrown while handling exception after service changes it says
which implies that that issue actually fixed it so that people now do see the rebuild message and it is helpful. However looking at the before and after screenshots in the issue summary it's obvious that @znerol is correct and the rebuild message is not displayed anymore.
Do we ever want to direct people to rebuild.php and if so, when?
Comment #30
znerol commentedFiled #2548823: Display an error message if the container needs to be rebuilt. I guess this issue here is fixed?
Comment #31
alexpottLol. Okay I committed this accidentally (sorry everyone) as I wanted
to be discussed here.
However as @znerol opened #2548823: Display an error message if the container needs to be rebuilt I think we can just have that discussion there.
Comment #33
damiankloip commentedThis broke the functionality that we had (I added, so biased :)) to NOT return 200 errors for uncaught exceptions. So seems like a regression. E.g. a fatal error would now return you a 200 response again. Unless I missed something, of course.
Comment #34
damiankloip commentedNevermind, I think it might just be me and this works great.
Comment #35
pjcarly commentedI'm wondering what the status of this issue is. It is marked as closed / fixed. But as far as I understand this hasn't been implemented in Core.
I'm running into a situation where this might be a solution for my problem. Explained here: https://drupal.stackexchange.com/questions/288697/handle-nested-exceptio...
The fact that the default Drupal exception handler doesn't rethrow a catched exception is causing some headache.
Comment #36
akhilavnairHi,
Is there any alternative way to handle custom exceptions for database settings.