-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpKernel] Add "handle-all-throwables option to handle thrown
Error in addition to
Exception`
#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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
76a8b23
to
1a26822
Compare
Thank you. What is the plan for 7.0? Just to change the default behaviour without warning? |
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. |
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). |
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:
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.) |
Two more options: 3. a setter/wither, 4. a decorator. |
👍 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. |
1a26822
to
00999b2
Compare
I think there are two questions here.
I think (Please confirm) what we are happy to do 2. But @nicolas-grekas is hesitant about 1. Except for the potential cost of migrations, is there any other reason we should not change the defaults? |
f480d00
to
d74ea89
Compare
HttpKernel
to handle thrown Error
in addition to Exception
HttpKernel
to handle thrown Error
in addition to Exception
_handle_all_throwables
to allow HttpKernel
to handle thrown Error
in addition to Exception
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 catch While considering your questions, I figured out another approach that might be a better fit. 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 deprecating not 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? |
@@ -30,15 +29,12 @@ protected function setUp(): void | |||
public function testArgumentValueResolverDisabled() | |||
{ | |||
$client = $this->createClient(['test_case' => 'Uid', 'root_config' => 'config_disabled.yml']); | |||
$client->catchExceptions(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need ExceptionSubscriber
because we can do this instead.
I'd throw in another option: Change the interface of the On Symfony 7, this could look like this: interface HttpKernelInterface
{
public const MAIN_REQUEST = 1;
public const SUB_REQUEST = 2;
public function handle(
Request $request,
int $type = self::MAIN_REQUEST,
CatchThrowables $catch = CatchThrowables::AllThrowables
): Response;
}
enum CatchThrowables
{
case AllThrowables;
case ExceptionsOnly; // like $catch === true on 6.1
case None; // like $catch === false on 6.1
} We should be able to create a smooth upgrade path for that. |
I considered this @derrabus but I don't see any smooth upgrade path to make it happen. Do you have one in mind? |
For 6.2, we can add the enum already comment out the interface HttpKernelInterface
{
public const MAIN_REQUEST = 1;
public const SUB_REQUEST = 2;
public function handle(
Request $request,
int $type = self::MAIN_REQUEST,
/* CatchThrowables $catch = CatchThrowables::AllThrowables, */
): Response;
} Our |
Actually, I just realized that 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 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. |
Any other input here? I don't want us to release the deprecation if that's not what we want. |
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. |
d74ea89
to
bfbc8f7
Compare
bfbc8f7
to
fcc3d39
Compare
There was a problem hiding this 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.
After talking with ppl in the core-team, I updated the implementation:
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 deprecation if we want everybody to use it by then. |
d82599c
to
c7f9ad4
Compare
So basically, we revert the deprecation and change the name of the config flag? That sounds good to me. Thanks. 👍🏻 |
Basically yes. We also remove |
There was a problem hiding this 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`
c7f9ad4
to
8604d3a
Compare
Thank you all for the review! |
_handle_all_throwables
to allow HttpKernel
to handle thrown Error
in addition to Exception
option to
HttpKernel to handle thrown
Error in addition to
Exception`
option to
HttpKernel to handle thrown
Error in addition to
Exception` option to handle thrown
Error in addition to
Exception`
This PR was merged into the 2.x-dev branch. Discussion ---------- [Tests] Remove unnecessary 6.2 config since symfony/symfony#47467 Commits ------- 005757f [Tests] Remove unnecessary 6.2 config
This PR was squashed before being merged into the 0.x-dev branch. Discussion ---------- [Tests] Remove unnecessary 6.2 config since symfony/symfony#47467 Commits ------- a279ded [Tests] Remove unnecessary 6.2 config
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 also