[Symfony 6] HttpKernel should opt-in to catching `\Throwable`

Created on 21 August 2022, over 2 years ago
Updated 4 March 2024, 9 months ago

Problem/Motivation

So I've been working on making exceptions sent to the client match the format of the request (or, the route, if it really should only speak one format) over at #3304981: JSON and other serialization formats should handle non-4xx exceptions, too. β†’ .

While testing this locally, I had the happy accident of writing some code which threw not an \Exception but a \TypeError, which is not an ancestor of \Exception but rather \Throwable. This resulted in a counterintuitive result where I got the ugly, last-ditch error formatter instead of my preferred formatted one.

A bit of tracing led me to discover that since Drupal 9 is still "stuck" on Symfony 4.4, the HttpKernel component only catches \Exception.

This was changed in April for Symfony 6, where the Kernel can now catch Throwables.

Interestingly, this functionality is not "on" by default, for BC reasons. (That is, the default is to only still catch \Exception.) It will, however, be the only behavior from Symfony 7.

I think Drupal should catch all the things and give them proper treatment in error handling. I've overridden the HttpKernel (I know...) on my project, but to opt-in to this behavior all we need to do is set a container parameter... and that means of course that end users can opt back out if a project needs time to prepare for Symfony 7.

This also requires changes to `InstallerRedirectTrait` and `ExceptionJsonSubscriber` which should should typehint on \Throwable. This is backwards-compatible of course because \Throwable includes \Exception.

I'm marking this major because I think it could get in "in time" for this to be a Change Record for 10.0.0? But since it's new behavior in Symfony 6, which Drupal 9 does not support, it does not need a deprecation in the same way as other code? I think?

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ“Œ Task
Status

Fixed

Version

10.0 ✨

Component
BaseΒ  β†’

Last updated about 11 hours ago

Created by

πŸ‡ΊπŸ‡ΈUnited States bradjones1 Digital Nomad Life

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024