Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[FrameworkBundle][HttpKernel] Add deprecation warning to showHttpKernel::handle() will catch throwables#45997

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:6.2fromNyholm:http-kernel-throwable
Jun 25, 2022

Conversation

@Nyholm
Copy link
Member

@NyholmNyholm commentedApr 11, 2022
edited
Loading

QA
Branch?6.2
Bug fix?no
New feature?no
Deprecations?yes
TicketsFix#16205
LicenseMIT
Doc PRsymfony/symfony-docs#...

I suggest that starting from Symfony 7.0 theHttpKernel will start to catch\Throwable and convert them to aResponse.

This was first asked in#16205, I face a similar issue with Runtime component and Bref..


The reason I push for this change is to embrace the request/response workflow of the Kernel without trusting the custom error handler. In an environment where you serve multiple requests with the same PHP process (read: RoadRunner, Swoole, Bref) you would write something like:

$kernel =newKernel('prod',false);while (true) {$request =/* create sf request from custom environment */  try {$response =$kernel->handle(request);return ResponseConverter::convert($response);  }catch (\Throwable$e) {exit(1);  }}

(pseudo code of course. Here is areal example)

Theexit(1) means a hard crash. For Bref Runtime it would result in a 500 error from API-gateway. Since the\Throwable is caught, the Symfony error handler is not used. If we would not to catch the\Throwable, then the Symfony error handler would be used, but it would print a Response instead of returning it. (Printing a response will just add HTML on the CLI...)


Other PRs and issues related to this:

I'm happy to let theHttpKernel to catch the\Throwable exception right now, but I thought this very conservative PR would have a higher change to get merged.

Also note that we do not specify any behaviour on ourHttpKernelInterface


To remove the deprecation message you need to add this to your config:

framework:catch_all_throwables:true

FabienPapet reacted with thumbs up emojiderrabus reacted with rocket emoji
@stof
Copy link
Member

A deprecation for which there is no way to opt-in for the new behavior is bad: it does not help migrating and will annoy people seeing it without being able to get rid of it.

@Nyholm
Copy link
MemberAuthor

Hm. You are very correct. Thank you. Do you have a suggestion on how to make an opt-in?

@stof
Copy link
Member

Well, you would need some kind of configuration parameter that can turn on the catching of errors.

@Nyholm
Copy link
MemberAuthor

Thank you for the review. I've update the PR with a way to opt-in to the new behaviour. I've also added some tests.

@Nyholm
Copy link
MemberAuthor

Psalm and Fabbot are both false negatives. It seams like the 8.2 test fails for unrelated reasons.

PHPUnit 8.1 low-deps fails because of this PR. Any suggestions how I could fix them?

@derrabus
Copy link
Member

Thank you very much for bringing this topic up again. I like how you allow to opt-in to the new behavior.

PHPUnit 8.1 low-deps fails because of this PR. Any suggestions how I could fix them?

The lazy fix would be to add conflict rules to the composer.json files of SecurityBundle and WebProfilerBundle, for FrameworkBundle < 6.1. The alterantive would be to make the test setup for the bundles more complex by setting/removing that option conditionally and I'm not sure that's worth it.

@Nyholm
Copy link
MemberAuthor

Thank you for the feedback. I've updated the PR.

@NyholmNyholmforce-pushed thehttp-kernel-throwable branch from67077c1 to08ce868CompareMay 1, 2022 07:57
@Nyholm
Copy link
MemberAuthor

The PR is rebased and updated.

status: Waiting for review

@fabpotfabpot modified the milestones:6.1,6.2May 20, 2022
@NyholmNyholmforce-pushed thehttp-kernel-throwable branch 4 times, most recently from77bb69f toa5acdbbCompareMay 29, 2022 11:12
@Nyholm
Copy link
MemberAuthor

The PR is updated for 6.2. Fabbot is a false negative and the PHP 8.2 test fail is unrelated.

I would be happy to get another review on this. I believe it is ready to merge

@Nyholm
Copy link
MemberAuthor

Nyholm commentedMay 29, 2022
edited
Loading

Thank you for the review. I've applied the changes.

derrabus reacted with thumbs up emojiderrabus reacted with rocket emoji

@carsonbotcarsonbot changed the titleAdd deprecation warning to show HttpKernel::handle() will catch throwables[FrameworkBundle][HttpKernel] Add deprecation warning to show HttpKernel::handle() will catch throwablesJun 14, 2022
@derrabusderrabus mentioned this pull requestJun 14, 2022
publicstaticfunctiongetExceptions():array
{
$exceptions =self::$exceptions;
self::$exceptions = [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

For a getter method I would not expect the method to modify the object's state but to be able to call the method several times with the same result.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I'll name thisresetExceptions()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Now it's not really clear that I could use this method retrieve the list of all caught exceptions. What about adapting the schema used for methods in the SPL and use something likeshiftAll()?

@Nyholm
Copy link
MemberAuthor

I've applied all changes and the CI is green

@NyholmNyholmforce-pushed thehttp-kernel-throwable branch from98e1a72 toa906e6cCompareJune 16, 2022 16:30
@Nyholm
Copy link
MemberAuthor

I've applied the suggested changes. I've rebased the PR and the tests are green.

Could I get a final round of reviews?

Copy link
Contributor

@HeahDudeHeahDude left a comment
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

$this->argumentResolver =$argumentResolver ??newArgumentResolver();
$this->catchThrowable =$catchThrowable;
if (!$catchThrowable) {
trigger_deprecation('symfony/http-kernel','6.2','Starting from 7.0, "%s::handle()" will catch \Throwable exceptions and convert them to HttpFoundation responses.',self::class);
Copy link
Contributor

@HeahDudeHeahDudeJun 16, 2022
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This depreciation message is not actionable. It should tell to passtrue as last argument to get rid of it.

Although this would still not be the right fix in the framework context, since thecatch_all_throwables option needs to be set totrue.
Maybe the configuration needs a->validate() node to trigger onfalse with the "good" message.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I've updated the exception message.

Maybe the configuration needs a ->validate() node to trigger on false with the "good" message.

Hm.. Yeah. But isn't that overkill?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I can see two paths. Once you get rid of the deprecation you should be ready for 7.0, but in this case it means passingtrue instead offalse.

  • Removing the argument and the config node could be done in 8.0, once first deprecated in 7.1.

  • However removing the arg as it seems to be expected in 7.0 won't break, but will make passing the arg some dead code without notice. Also removing the config node in 7.0 would be a BC break if devs continue to define it totrue.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Since the constructor argument and config is part of the deprecation layer they will both be removed in 7.0.
Aren't we overthinking now?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

choices_as_values option was used for Symfony 2 deprecation layer, but deprecated in 3.1,
logout_on_user_change option was used in Symfony 3 deprecation layer and deprecated in 4.1 and so on.

The BC should be to not change your code when upgrading to 7.0, in this case changingfalse totrue would make it work, but once done, another change would be required to remove config and arg, so they must still exist before we can safely remove them.

In other words, the deprecation layer itself cannot be deprecated in 6.x nor removed in 7.0, it needs to be deprecated in 7.1.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Maybe the configuration needs a ->validate() node to trigger on false with the "good" message.

Hm... Yeah. But isn't that overkill?

Well, the problem I see is that most devs using the framework do not even know there is anHttpKernel service nor how to change this arg.
However, mentioning the config key in this message from the component feels wrong.

@HeahDude
Copy link
Contributor

It would be nice to have this default totrue with the 6.2 recipe for new projects (and smooth upgrade withcomposer recipes:update).

Nyholm reacted with thumbs up emoji

@OskarStarkOskarStark changed the title[FrameworkBundle][HttpKernel] Add deprecation warning to show HttpKernel::handle() will catch throwables[FrameworkBundle][HttpKernel] Add deprecation warning to showHttpKernel::handle() will catch throwablesJun 16, 2022
@NyholmNyholmforce-pushed thehttp-kernel-throwable branch from96fefac to7977a15CompareJune 25, 2022 07:18
@Nyholm
Copy link
MemberAuthor

I've rebased the PR and squashed the commits.

The CI failures are not related to this PR. Could I ask you to review this PR again to decide if it is good enough to merge.

@fabpot
Copy link
Member

Thank you@Nyholm.

@Nyholm
Copy link
MemberAuthor

Awesome. Thank you for merging.

Big thank you to all reviewers too

nicolas-grekas added a commit that referenced this pull requestOct 18, 2022
…es` to allow `HttpKernel` to handle thrown `Error` in addition to `Exception` (nicolas-grekas)This PR was squashed before being merged into the 6.2 branch.Discussion----------[HttpKernel] Add request attribute `_handle_all_throwables` to allow `HttpKernel` to handle thrown `Error` in addition to `Exception`| Q             | A| ------------- | ---| Branch?       | 6.2| Bug fix?      | no| New feature?  | no| Deprecations? | no| Tickets       | -| License       | MIT| Doc PR        | -I understand the motivation behind#45997 but I don't think the deprecation is worth the migration cost on *all* users of Symfony.The burden of enabling this setting should only be on use cases where getting a response back is needed.The previous behavior was just fine in common situations./cc `@catch56` for Drupal FYI/cc `@Nyholm` alsoCommits-------8604d3a [HttpKernel] Add request attribute `_handle_all_throwables` to allow `HttpKernel` to handle thrown `Error` in addition to `Exception`
weaverryan added a commit to symfony/webpack-encore-bundle that referenced this pull requestOct 19, 2022
…st to fix CI (jmsche)This PR was merged into the main branch.Discussion----------Rename catch_all_throwables to handle_all_throwables in test to fix CILittle fix required to make CI pass again :)The `catch_all_throwables` parameter was renamed by this PR:symfony/symfony#45997Commits-------aae2142 Rename catch_all_throwables to handle_all_throwables in test to fix CI
@fabpotfabpot mentioned this pull requestOct 24, 2022
Keemosty12 added a commit to Keemosty12/webpack-encore-bundle that referenced this pull requestJun 12, 2025
…st to fix CI (jmsche)This PR was merged into the main branch.Discussion----------Rename catch_all_throwables to handle_all_throwables in test to fix CILittle fix required to make CI pass again :)The `catch_all_throwables` parameter was renamed by this PR:symfony/symfony#45997Commits-------aae2142 Rename catch_all_throwables to handle_all_throwables in test to fix CI
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@OskarStarkOskarStarkOskarStark left review comments

@xabbuhxabbuhxabbuh left review comments

@fabpotfabpotfabpot approved these changes

@derrabusderrabusderrabus approved these changes

@wouterjwouterjAwaiting requested review from wouterjwouterj is a code owner

@chalasrchalasrAwaiting requested review from chalasrchalasr is a code owner

+1 more reviewer

@HeahDudeHeahDudeHeahDude left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

6.2

Development

Successfully merging this pull request may close these issues.

[HttpKernel] Exceptions Responses are automatically sent

8 participants

@Nyholm@stof@derrabus@HeahDude@fabpot@OskarStark@xabbuh@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp