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

[HttpKernel] Add "handle-all-throwables option to handle thrownError in addition toException`#47467

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
nicolas-grekas merged 1 commit intosymfony:6.2fromnicolas-grekas:hk-catchall
Oct 18, 2022

Conversation

@nicolas-grekas
Copy link
Member

@nicolas-grekasnicolas-grekas commentedSep 2, 2022
edited
Loading

QA
Branch?6.2
Bug fix?no
New feature?no
Deprecations?no
Tickets-
LicenseMIT
Doc PR-

I understand the motivation behind#45997 but I don't think the deprecation is worth the migration cost onall 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 also

@Nyholm
Copy link
Member

Thank you.

What is the plan for 7.0? Just to change the default behaviour without warning?

@catch56
Copy link

Just to say for Drupal this was an easy change for us - we had to add the parameter to our container definition, and update one test (it tests what happens with an specific uncaught exception, that is now caught), nothing else.

I think this also means that if the behaviour changes without warning in Symfony 7, this would also be OK - we'd still have to update one test.

@nicolas-grekas
Copy link
MemberAuthor

nicolas-grekas commentedSep 3, 2022
edited
Loading

What is the plan for 7.0? Just to change the default behaviour without warning?

The plan on my side should be to keep things as is, aka no change of the default. It's fine to let Error throw out on short-living processes,and in tests. The deprecation + behavior change would require ppl to 1. opt-in for the new default and 2. update their test cases. Both worry me, like in "not worth it, cost is too high compared to the benefits". (+ I'm not sure it's good defaults to swallow Error, in tests especially).

@nicolas-grekas
Copy link
MemberAuthor

nicolas-grekas commentedSep 3, 2022
edited
Loading

Here is another thought I had when looking at your use case@Nyholm: should it be possible to handle exceptions without cooperation from configuration? If that'd be desirable, there could be two ways to do it:

  1. add an argument to handle() to say "do catchError"
  2. pass false as $catch to handle, then catch outside and add a method to render an exception, which kinda means making handleThrowable public.

Did you consider those options? Would they fit better for you? (as in: no change in config to support both long and short-living runtimes.)

@nicolas-grekas
Copy link
MemberAuthor

Two more options: 3. a setter/wither, 4. a decorator.

@chalasr
Copy link
Member

chalasr commentedSep 3, 2022
edited
Loading

👍 for reverting the deprecation as short-lived processes is still the main use case. No strong opinion about the alternative, the config option is fine to me.

@Nyholm
Copy link
Member

I think there are two questions here.

  1. Do we want change the defaults or not.
  2. Do we want to support proper handling ofError (ie non-Exceptions butThrowable.

I think (Please confirm) what we are happy to do 2. But@nicolas-grekas is hesitant about 1.
What is really important for me is that we do 2. If that is opt-in or default.. it doesn't matter.

Except for the potential cost of migrations, is there any other reason we should not change the defaults?
Wouldn't it bring a more coherent user experience?

@nicolas-grekasnicolas-grekasforce-pushed thehk-catchall branch 2 times, most recently fromf480d00 tod74ea89CompareSeptember 29, 2022 08:09
@nicolas-grekasnicolas-grekas changed the title[HttpKernel] Remove deprecation when catch_all_throwables=false[HttpKernel] Add request attribute _handle_all_throwables to allowHttpKernel to handle thrownError in addition toExceptionSep 29, 2022
@nicolas-grekasnicolas-grekas changed the title[HttpKernel] Add request attribute _handle_all_throwables to allowHttpKernel to handle thrownError in addition toException[HttpKernel] Add request attribute_handle_all_throwables to allowHttpKernel to handle thrownError in addition toExceptionSep 29, 2022
@nicolas-grekas
Copy link
MemberAuthor

nicolas-grekas commentedSep 29, 2022
edited
Loading

Thanks for having a look. You're right about 1. and 2. I know that we already tried doing this change and that this broke some apps that did expect to catchError in theirindex.php file, before Runtime was a thing.

While considering your questions, I figured out another approach that might be a better fit.
Instead of adding a constructor argument, the behavior can now be configured via a request attribute. I named it_handle_all_throwables. When it's set totrue, all throwables are handled the same way as exceptions.
And I turned on this flag in the Runtime component.

This means ppl that use modern stacks (aka Runtime) will have the new behavior enabled by default. I think this is safe and legit because Runtime is expected to work on both on long-running and short-living engines.

And ppl that still use the old index.php won't see any difference.

If we want to enable this behavior by default, we can still consider deprecatingnot setting the new attribute in >= 7.1, and handle all throwables by default in 8.0. But meanwhile, we provide a smooth upgrade.

Makes sense?

publicfunctiontestArgumentValueResolverDisabled()
{
$client =$this->createClient(['test_case' =>'Uid','root_config' =>'config_disabled.yml']);
$client->catchExceptions(false);
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

We don't needExceptionSubscriber because we can do this instead.

@derrabus
Copy link
Member

derrabus commentedSep 29, 2022
edited
Loading

While considering your questions, I figured out another approach that might be a better fit. Instead of adding a constructor argument, the behavior can now be configured via a request attribute. I named it_handle_all_throwables. When it's set totrue, all throwables are handles as exceptions right now. And I turned on this flag in the Runtime component.

I'd throw in another option: Change the interface of theHttpKernelInterface::handle() method. It already has a parameter where we can control if exceptions are caught. Before we add a request attribute that is not really well discoverable for developers, we could think about repurposing that parameter.

On Symfony 7, this could look like this:

interface HttpKernelInterface{publicconstMAIN_REQUEST =1;publicconstSUB_REQUEST =2;publicfunctionhandle(Request$request,int$type =self::MAIN_REQUEST,CatchThrowables$catch = CatchThrowables::AllThrowables    ):Response;}enum CatchThrowables{case AllThrowables;case ExceptionsOnly;// like $catch === true on 6.1case None;// like $catch === false on 6.1}

We should be able to create a smooth upgrade path for that.

@nicolas-grekas
Copy link
MemberAuthor

I considered this@derrabus but I don't see any smooth upgrade path to make it happen. Do you have one in mind?

@derrabus
Copy link
Member

For 6.2, we can add the enum already comment out the$catch parameter. It's optional, so downstream implementations of the interface with the oldbool $catch = true parameter should not be broken by that.

interface HttpKernelInterface{publicconstMAIN_REQUEST =1;publicconstSUB_REQUEST =2;publicfunctionhandle(Request$request,int$type =self::MAIN_REQUEST,/* CatchThrowables $catch = CatchThrowables::AllThrowables, */    ):Response;}

OurHttpKernel implementation triggers a deprecation if$catch is not passed explicitly or if a boolean is passed.

@nicolas-grekas
Copy link
MemberAuthor

nicolas-grekas commentedSep 29, 2022
edited
Loading

Actually, I just realized that$catch and the new behavior are not entirely connected. If you look at the code, wealways catch exceptions, even if$catch isfalse. When it's false, we rethrow the exception, but before that,we callfinishRequest().
Errors right now are ignored. When we'll go withhandling them too, we'll still need to decide if we'll also want to$catch them, with this definition of$catch that I just described for exceptions.

There is another thing that the attribute provides and that highlights the difference: the attribute I'm proposing allows deciding if errors should be handled only for the main request or also for subrequests. That's not something that$catch is meant to control.

In the current patch, only the main request will handle errors. I think that's appropriate.

You mention that adding an attribute is not really well discoverable. That's true, but the vast majority of devs won't have to discover it because this is outside of the scope of coding in Symfony. Only ppl that work at the runtime/bootstrap level might be interested in using that attribute. Our Runtime component will enable the flag by default and done.

IF we really want to make this more discoverable, I suggested an approach that could work for v7.1+/8.0. By the time, we might have more clues on the topic and decide if we need something else.

@nicolas-grekas
Copy link
MemberAuthor

Any other input here? I don't want us to release the deprecation if that's not what we want.

@nicolas-grekas
Copy link
MemberAuthor

enum CatchThrowables

About this proposal, I'm not convinced it makes sense: exposing the behavior as public API doesn't look desired to me as the difference is too subtle. Better keep this as an implementation detail IMHO.

chalasr reacted with thumbs up emoji

Copy link
Member

@fabpotfabpot left a comment

Choose a reason for hiding this comment

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

I like it, especially with the related PR on runtime.

@nicolas-grekas
Copy link
MemberAuthor

nicolas-grekas commentedOct 18, 2022
edited
Loading

After talking with ppl in the core-team, I updated the implementation:

  • the new argument on HttpKernel is back, but it's named handleAllThrowables since we discovered that's a more appropriate name, and more importantly, it defaults to false and it comes withno deprecation attached
  • the request attribute is gone
  • the config option is back also, underframework.handle_all_throwables. Name updated also, and no explicit default value to keep things simple, and anticipate a future where the option might go away.

People that use a long-running runtime SHOULD enable the new option (that's doc to write on php-runtime@Nyholm), and ppl on short-lived runtime MIGHT enable it without any nasty side-effect, unless they rely on the previous behavior.

This means we SHOULD enable the option by default in the recipe for 6.2.

As ppl migrate to 6.2+, they will sync their recipes and the majority should get the option turned on by 7.1. This should make it cheap to trigger a deprecationif we want everybody to use it by then.

@derrabus
Copy link
Member

So basically, we revert the deprecation and change the name of the config flag? That sounds good to me. Thanks. 👍🏻

@nicolas-grekas
Copy link
MemberAuthor

Basically yes. We also removeTest\ExceptionSubscriber because$client->catchExceptions(false); already exists and works great for the need.

Copy link
Member

@NyholmNyholm left a comment

Choose a reason for hiding this comment

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

Thank you!

…`HttpKernel` to handle thrown `Error` in addition to `Exception`
@nicolas-grekas
Copy link
MemberAuthor

Thank you all for the review!

@nicolas-grekasnicolas-grekas deleted the hk-catchall branchOctober 18, 2022 15:44
@nicolas-grekasnicolas-grekas changed the title[HttpKernel] Add request attribute_handle_all_throwables to allowHttpKernel to handle thrownError in addition toException[HttpKernel] Add "handle-all-throwables option toHttpKernel to handle thrownError in addition toException`Oct 26, 2022
@nicolas-grekasnicolas-grekas changed the title[HttpKernel] Add "handle-all-throwables option toHttpKernel to handle thrownError in addition toException`[HttpKernel] Add "handle-all-throwables option to handle thrownError in addition toException`Oct 26, 2022
ogizanagi added a commit to Elao/PhpEnums that referenced this pull requestNov 8, 2022
This PR was merged into the 2.x-dev branch.Discussion----------[Tests] Remove unnecessary 6.2 configsincesymfony/symfony#47467Commits-------005757f [Tests] Remove unnecessary 6.2 config
ogizanagi added a commit to StenopePHP/Stenope that referenced this pull requestNov 18, 2022
This PR was squashed before being merged into the 0.x-dev branch.Discussion----------[Tests] Remove unnecessary 6.2 configsincesymfony/symfony#47467Commits-------a279ded [Tests] Remove unnecessary 6.2 config
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot approved these changes

@stofstofstof approved these changes

@NyholmNyholmNyholm approved these changes

@chalasrchalasrchalasr approved these changes

@wouterjwouterjAwaiting requested review from wouterjwouterj is a code owner

Assignees

No one assigned

Projects

None yet

Milestone

6.2

Development

Successfully merging this pull request may close these issues.

8 participants

@nicolas-grekas@Nyholm@catch56@chalasr@derrabus@fabpot@stof@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp