-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle][BC Break] Adding http_exception_listener introduces BC break to exception handling #27212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The description is correct since that's exactly what we introduced in #26138. |
I have a bundle with a custom exception listener that handles specific exceptions selectively. |
I'm sorry I still don't totally understand where the bug is. To help move forward, here are some comments.
Correct, that's how exception handling works. The exception doesn't throw back if a listener deals with it, which is what we added recently for HTTP exceptions only. Was your app doing something special with these exceptions? If yes, shouldn't this extra logic be moved to a listener instead. If no, then the issue is not here specifically, isn it ?
yes, that feels like normal event dispatching; shouldn't your bundle be able to deal with this since that's regular request/response lifecycle?
a closure is a valid value for the _controller attribute so that this looks like the issue is on your side here.
Thanks for the reproducer. Reading it, I continue to think this illustrate a very specific expectation for the request/response/exception lifecycle workflow. I feel like any other bundle could alter the expectations you describe here, so that the issue might be in your app, it being too tightly coupled with these expectations. I don't feel like this is something that we should qualify as a BC break or regression. Of course, I might miss the obvious, if anyone else wants to chime in please do! |
It is a listener, which was broken by adding ExceptionListener which steals the event now.
Yes and no. Since your listener is now stealing the event and converting it to Response object, it's impossible to do custom handling & conversion.
It breaks a very basic assumption that was valid for years: Symfony does not catch thrown exceptions.
Agreed, the code is not currently compatible with closure controllers, but this is just one of the consequences of the BC break though, the real issue is completely changed lifecycle for exception handling - it now steals the exception event, executes a SUB_REQUEST and modifies output.
Not really happy to hear that, especially given the SF BC promise. I'm afraid I'll have to completely rewrite part of our bundle for exception handling and also rewrite the code that expected exceptions to actually be thrown and causing fatal error. |
So now your listener is executed after the new Symfony exception listener? Can you change priorities? |
Yes for the part where I want to handle the exceptions. Either way, making a consumer change anything, even priorities, clearly is a BC break on its own. |
we can lower the priority of the added exception listener and that would fix this part of the issue, isn't it?
this part is more controversial: I would argue that you should not suppose what other listeners do. If you really need the exception our of the listener stack, I'd say you should throw in yours: Note that I'm just trying to find the best middle ground between your expectations and the ones described in #25844, which justified the new listener. If you have another approach that would handle this, ideas welcome. |
Sounds like a feasible compromise, although it still requires some work
That's a bit tricky question. So a tricky answer would be: lower than the lowest priority used by a user. :) I guess that's not what you wanted to hear though. I don't if there are some recommendations like you should not use priorities outside X-Y range, if not, how about something like -2048 (since the Either way it will still require some amount of work to adopt to this lifecycle change:
Ad #25844: |
looks like #27440 is related to this too |
See fix in #27505 |
Subrequests are a thing since years (and TwigBundle is using subrequests to render error pages since Symfony 2.0). If you want your listener to deal only with the master request, it is very easy to check for it: symfony/src/Symfony/Component/HttpKernel/EventListener/SaveSessionListener.php Lines 29 to 31 in 4cd6477
|
…templating is not installed (cilefen)" (nicolas-grekas) This PR was merged into the 3.4 branch. Discussion ---------- Revert "bug #26138 [HttpKernel] Catch HttpExceptions when templating is not installed (cilefen)" | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #27212 | License | MIT | Doc PR | - This reverts commit b213c5a, reversing changes made to 61af0e3. This breaks BC and is more like a new feature, let's move this on master. Commits ------- c6acad7 Revert "bug #26138 [HttpKernel] Catch HttpExceptions when templating is not installed (cilefen)"
(commit reverted) |
Thanks for the info. 👍 I do understand the reasoning why someone wanted this to be the default behavior though - would the proposal above (adding a switch for this behavior to FrameworkBundle 4.x) be maybe a valid compromise for both lands?
|
Symfony version(s) affected: 4.0.9/4.1.0-BETA1
Description
Commit 4e527aa added a service
http_exception_listener
. This registers a system-wide exception handler that sets request's_controller
attribute to a closure duringkernel.exception
.Also this closure controller generates a response on the event. As a consequence of that, this triggers listeners on
kernel.response
event - with_controller
as a closure instead of previously not being invoked at all, and the generated response instead of null.How to reproduce
Failing test case provided separately in #27213.
Additional context
Encountered in API-only application, no templating etc., only custom request/response handling and custom exception handling.
The text was updated successfully, but these errors were encountered: