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 now handle non-4xx exceptions.

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

Issue fork drupal-3304991

Command icon 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

bradjones1 created an issue. See original summary.

bradjones1’s picture

Component: system.module » base system
Status: Active » Needs review
andypost’s picture

I think it needs @todo link and follow-up to remove new container param in 11.0.x

bradjones1’s picture

bradjones1’s picture

andypost’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Symfony 6
Parent issue: » #3161889: [META] Symfony 6 compatibility

Bot should be green

andypost’s picture

catch’s picture

Status: Reviewed & tested by the community » Needs review

Test failure is quickedit so unrelated.

I can't really think of a situation where someone would need to change this back, so wondering if we can just change the service definition without the new parameter (and hence no follow-up, or at least the follow-up would just remove passing the parameter). Someone could still alter the service definition itself to change the parameter if they really need to.

bradjones1’s picture

I'm ambivalent, fine either way with it. I'm often told that X or Y change needs a deprecation, and this is a change in behavior... so I erred on the side of completeness. But it's a 1-line change without it. Just hard-code in true. And as you mention, people can always alter the definition.

catch’s picture

Status: Needs review » Needs work

I think we should just hard-code it, it makes it slightly harder to alter but not impossible - and as you say it's a behaviour change rather than an API change where we can't do a formal deprecation anyway.

bradjones1’s picture

Status: Needs work » Needs review

Done.

catch’s picture

Status: Needs review » Reviewed & tested by the community

That looks great thank you.

bradjones1’s picture

Updated CR.

alexpott’s picture

Version: 10.1.x-dev » 10.0.x-dev
Priority: Major » Normal
Status: Reviewed & tested by the community » Fixed

Committed and pushed c86d7ad0c9 to 10.1.x and bc0acf7354 to 10.0.x. Thanks!

I really can't see why this is a major issue. Changed to a normal one.

  • alexpott committed c86d7ad on 10.1.x
    Issue #3304991 by bradjones1, andypost, catch: [Symfony 6] HttpKernel...

  • alexpott committed bc0acf7 on 10.0.x
    Issue #3304991 by bradjones1, andypost, catch: [Symfony 6] HttpKernel...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.