Skip to content

Commit 48ae189

Browse files
[HttpKernel] Add request attribute _handle_all_throwables to allow HttpKernel to handle thrown Error in addition to Exception
1 parent 108a324 commit 48ae189

File tree

11 files changed

+7
-78
lines changed

11 files changed

+7
-78
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ CHANGELOG
66

77
* Add `resolve-env` option to `debug:config` command to display actual values of environment variables in dumped configuration
88
* Add `NotificationAssertionsTrait`
9-
* Add option `framework.catch_all_throwables` to allow `Symfony\Component\HttpKernel\HttpKernel` to catch all kinds of `Throwable`
9+
* Add option `framework.handle_all_throwables` to allow `Symfony\Component\HttpKernel\HttpKernel` to handle all kinds of `Throwable`
1010
* Make `AbstractController::render()` able to deal with forms and deprecate `renderForm()`
1111
* Deprecate the `Symfony\Component\Serializer\Normalizer\ObjectNormalizer` and
1212
`Symfony\Component\Serializer\Normalizer\PropertyNormalizer` autowiring aliases, type-hint against

DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public function getConfigTreeBuilder(): TreeBuilder
133133
->scalarNode('error_controller')
134134
->defaultValue('error_controller')
135135
->end()
136-
->booleanNode('catch_all_throwables')->defaultFalse()->info('HttpKernel will catch all kinds of \Throwable')->end()
136+
->booleanNode('handle_all_throwables')->info('HttpKernel will handle all kinds of \Throwable')->end()
137137
->end()
138138
;
139139

DependencyInjection/FrameworkExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ public function load(array $configs, ContainerBuilder $container)
330330

331331
$container->getDefinition('locale_listener')->replaceArgument(3, $config['set_locale_from_accept_language']);
332332
$container->getDefinition('response_listener')->replaceArgument(1, $config['set_content_language_from_locale']);
333-
$container->getDefinition('http_kernel')->replaceArgument(4, $config['catch_all_throwables']);
333+
$container->getDefinition('http_kernel')->replaceArgument(4, $config['handle_all_throwables'] ?? false);
334334

335335
// If the slugger is used but the String component is not available, we should throw an error
336336
if (!ContainerBuilder::willBeAvailable('symfony/string', SluggerInterface::class, ['symfony/framework-bundle'])) {

Test/ExceptionSubscriber.php

Lines changed: 0 additions & 56 deletions
This file was deleted.

Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,6 @@ class_exists(SemaphoreStore::class) && SemaphoreStore::isSupported() ? 'semaphor
657657
'sanitizers' => [],
658658
],
659659
'exceptions' => [],
660-
'catch_all_throwables' => false,
661660
];
662661
}
663662
}

Tests/Functional/UidTest.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;
1313

14-
use Symfony\Bundle\FrameworkBundle\Test\ExceptionSubscriber;
15-
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller\UidController;
1614
use Symfony\Component\Uid\Ulid;
1715
use Symfony\Component\Uid\UuidV1;
1816
use Symfony\Component\Uid\UuidV4;
@@ -30,15 +28,12 @@ protected function setUp(): void
3028
public function testArgumentValueResolverDisabled()
3129
{
3230
$client = $this->createClient(['test_case' => 'Uid', 'root_config' => 'config_disabled.yml']);
31+
$client->catchExceptions(false);
3332

34-
$client->request('GET', '/1/uuid-v1/'.new UuidV1());
35-
$this->assertSame(500, $client->getResponse()->getStatusCode());
36-
$exceptions = ExceptionSubscriber::shiftAll();
37-
$this->assertCount(1, $exceptions);
38-
$exception = reset($exceptions);
33+
$this->expectException(\TypeError::class);
34+
$this->expectExceptionMessage('Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller\UidController::anyFormat(): Argument #1 ($userId) must be of type Symfony\Component\Uid\UuidV1, string given');
3935

40-
$this->assertInstanceOf(\TypeError::class, $exception);
41-
$this->assertStringContainsString(UidController::class.'::anyFormat(): Argument #1 ($userId) must be of type Symfony\Component\Uid\UuidV1, string given', $exception->getMessage());
36+
$client->request('GET', '/1/uuid-v1/'.new UuidV1());
4237
}
4338

4439
public function testArgumentValueResolverEnabled()

Tests/Functional/app/Uid/config_disabled.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,3 @@ framework:
55
http_method_override: false
66
uid:
77
enabled: false
8-
9-
services:
10-
Symfony\Bundle\FrameworkBundle\Test\ExceptionSubscriber:
11-
tags:
12-
- { name: kernel.event_subscriber }

Tests/Functional/app/config/framework.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ framework:
1111
enabled_locales: ['en', 'fr']
1212
session:
1313
storage_factory_id: session.storage.factory.mock_file
14-
catch_all_throwables: true
1514

1615
services:
1716
logger: { class: Psr\Log\NullLogger }

Tests/Kernel/ConcreteMicroKernel.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
8686
'http_method_override' => false,
8787
'secret' => '$ecret',
8888
'router' => ['utf8' => true],
89-
'catch_all_throwables' => true,
9089
]);
9190

9291
$c->setParameter('halloween', 'Have a great day!');

Tests/Kernel/MicroKernelTraitTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ protected function configureContainer(ContainerConfigurator $c): void
122122
$c->extension('framework', [
123123
'http_method_override' => false,
124124
'router' => ['utf8' => true],
125-
'catch_all_throwables' => true,
126125
]);
127126
$c->services()->set('logger', NullLogger::class);
128127
}

Tests/Kernel/flex-style/src/FlexStyleMicroKernel.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ protected function configureContainer(ContainerConfigurator $c): void
103103
$c->extension('framework', [
104104
'http_method_override' => false,
105105
'router' => ['utf8' => true],
106-
'catch_all_throwables' => true,
107106
]);
108107
}
109108
}

0 commit comments

Comments
 (0)