Skip to content

Commit 10a349c

Browse files
committed
feature #34309 [HttpKernel] make ExceptionEvent able to propagate any throwable (nicolas-grekas)
This PR was merged into the 4.4 branch. Discussion ---------- [HttpKernel] make ExceptionEvent able to propagate any throwable | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | no | Deprecations? | yes | Tickets | - | License | MIT | Doc PR | - An alternative to #34306. As a reminder, the goal of this series of PRs is to remove the `FatalThrowableError` wrapper that we introduced to seamlessly handle throwables when they were introduced in PHP 7. From the changelog of `HttpKernel`: * Deprecated methods `ExceptionEvent::get/setException()`, use `get/setThrowable()` instead * Deprecated class `ExceptionListener`, use `ErrorListener` instead And the final target: removed `Symfony\Component\ErrorHandler\Exception\ErrorException` (`FatalThrowableError` is already deprecated.) Commits ------- 6f67f0e [HttpKernel] make ExceptionEvent able to propagate any throwable
2 parents d5ba535 + 6f67f0e commit 10a349c

29 files changed

+393
-150
lines changed

UPGRADE-4.4.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ HttpKernel
154154
* Marked the `RouterDataCollector::collect()` method as `@final`.
155155
* The `DataCollectorInterface::collect()` and `Profiler::collect()` methods third parameter signature
156156
will be `\Throwable $exception = null` instead of `\Exception $exception = null` in Symfony 5.0.
157+
* Deprecated methods `ExceptionEvent::get/setException()`, use `get/setThrowable()` instead
158+
* Deprecated class `ExceptionListener`, use `ErrorListener` instead
157159

158160
Lock
159161
----

UPGRADE-5.0.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ HttpKernel
290290
* Removed `TranslatorListener` in favor of `LocaleAwareListener`
291291
* The `DebugHandlersListener` class has been made `final`
292292
* Removed `SaveSessionListener` in favor of `AbstractSessionListener`
293+
* Removed methods `ExceptionEvent::get/setException()`, use `get/setThrowable()` instead
294+
* Removed class `ExceptionListener`, use `ErrorListener` instead
293295
* Added new Bundle directory convention consistent with standard skeletons:
294296

295297
```

src/Symfony/Bundle/FrameworkBundle/Console/Application.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
use Symfony\Component\Console\Output\ConsoleOutputInterface;
2020
use Symfony\Component\Console\Output\OutputInterface;
2121
use Symfony\Component\Console\Style\SymfonyStyle;
22+
use Symfony\Component\Debug\Exception\FatalThrowableError;
2223
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
23-
use Symfony\Component\ErrorHandler\Exception\ErrorException;
2424
use Symfony\Component\HttpKernel\Bundle\Bundle;
2525
use Symfony\Component\HttpKernel\Kernel;
2626
use Symfony\Component\HttpKernel\KernelInterface;
@@ -211,7 +211,7 @@ private function renderRegistrationErrors(InputInterface $input, OutputInterface
211211
$this->doRenderThrowable($error, $output);
212212
} else {
213213
if (!$error instanceof \Exception) {
214-
$error = new ErrorException($error);
214+
$error = new FatalThrowableError($error);
215215
}
216216

217217
$this->doRenderException($error, $output);

src/Symfony/Bundle/FrameworkBundle/Resources/config/web.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
<argument type="service" id="error_renderer" />
9696
</service>
9797

98-
<service id="exception_listener" class="Symfony\Component\HttpKernel\EventListener\ExceptionListener">
98+
<service id="exception_listener" class="Symfony\Component\HttpKernel\EventListener\ErrorListener">
9999
<tag name="kernel.event_subscriber" />
100100
<tag name="monolog.logger" channel="request" />
101101
<argument>%kernel.error_controller%</argument>

src/Symfony/Bundle/FrameworkBundle/Tests/Kernel/ConcreteMicroKernel.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
2020
use Symfony\Component\Filesystem\Filesystem;
2121
use Symfony\Component\HttpFoundation\Response;
22-
use Symfony\Component\HttpKernel\Event\RequestEvent;
22+
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
2323
use Symfony\Component\HttpKernel\Kernel;
2424
use Symfony\Component\HttpKernel\KernelEvents;
2525
use Symfony\Component\Routing\RouteCollectionBuilder;
@@ -30,9 +30,9 @@ class ConcreteMicroKernel extends Kernel implements EventSubscriberInterface
3030

3131
private $cacheDir;
3232

33-
public function onKernelException(RequestEvent $event)
33+
public function onKernelException(ExceptionEvent $event)
3434
{
35-
if ($event->getException() instanceof Danger) {
35+
if ($event->getThrowable() instanceof Danger) {
3636
$event->setResponse(Response::create('It\'s dangerous to go alone. Take this ⚔'));
3737
}
3838
}

src/Symfony/Bundle/TwigBundle/Controller/PreviewErrorController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function previewErrorPageAction(Request $request, $code)
4343

4444
/*
4545
* This Request mimics the parameters set by
46-
* \Symfony\Component\HttpKernel\EventListener\ExceptionListener::duplicateRequest, with
46+
* \Symfony\Component\HttpKernel\EventListener\ErrorListener::duplicateRequest, with
4747
* the additional "showException" flag.
4848
*/
4949

src/Symfony/Component/Console/Application.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@
4242
use Symfony\Component\Console\Output\OutputInterface;
4343
use Symfony\Component\Console\Style\SymfonyStyle;
4444
use Symfony\Component\Debug\ErrorHandler as LegacyErrorHandler;
45-
use Symfony\Component\Debug\Exception\FatalThrowableError as LegacyFatalThrowableError;
45+
use Symfony\Component\Debug\Exception\FatalThrowableError;
4646
use Symfony\Component\ErrorHandler\ErrorHandler;
47-
use Symfony\Component\ErrorHandler\Exception\ErrorException;
4847
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
4948
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
5049
use Symfony\Contracts\Service\ResetInterface;
@@ -809,7 +808,7 @@ public function renderThrowable(\Throwable $e, OutputInterface $output): void
809808
@trigger_error(sprintf('The "%s::renderException()" method is deprecated since Symfony 4.4, use "renderThrowable()" instead.', __CLASS__), E_USER_DEPRECATED);
810809

811810
if (!$e instanceof \Exception) {
812-
$e = class_exists(ErrorException::class) ? new ErrorException($e) : (class_exists(LegacyFatalThrowableError::class) ? new LegacyFatalThrowableError($e) : new \ErrorException($e->getMessage(), $e->getCode(), E_ERROR, $e->getFile(), $e->getLine()));
811+
$e = class_exists(FatalThrowableError::class) ? new FatalThrowableError($e) : new \ErrorException($e->getMessage(), $e->getCode(), E_ERROR, $e->getFile(), $e->getLine());
813812
}
814813

815814
$this->renderException($e, $output);
@@ -848,7 +847,7 @@ protected function doRenderThrowable(\Throwable $e, OutputInterface $output): vo
848847
@trigger_error(sprintf('The "%s::doRenderException()" method is deprecated since Symfony 4.4, use "doRenderThrowable()" instead.', __CLASS__), E_USER_DEPRECATED);
849848

850849
if (!$e instanceof \Exception) {
851-
$e = class_exists(ErrorException::class) ? new ErrorException($e) : (class_exists(LegacyFatalThrowableError::class) ? new LegacyFatalThrowableError($e) : new \ErrorException($e->getMessage(), $e->getCode(), E_ERROR, $e->getFile(), $e->getLine()));
850+
$e = class_exists(FatalThrowableError::class) ? new FatalThrowableError($e) : new \ErrorException($e->getMessage(), $e->getCode(), E_ERROR, $e->getFile(), $e->getLine());
852851
}
853852

854853
$this->doRenderException($e, $output);

src/Symfony/Component/Debug/Exception/FatalErrorException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111

1212
namespace Symfony\Component\Debug\Exception;
1313

14-
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', FatalErrorException::class, \Symfony\Component\ErrorHandler\Exception\ErrorException::class), E_USER_DEPRECATED);
14+
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', FatalErrorException::class, \Symfony\Component\ErrorHandler\Error\FatalError::class), E_USER_DEPRECATED);
1515

1616
/**
1717
* Fatal Error Exception.
1818
*
1919
* @author Konstanton Myakshin <koc-dp@yandex.ru>
2020
*
21-
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\Exception\ErrorException instead.
21+
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\Error\FatalError instead.
2222
*/
2323
class FatalErrorException extends \ErrorException
2424
{

src/Symfony/Component/Debug/Exception/FatalThrowableError.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111

1212
namespace Symfony\Component\Debug\Exception;
1313

14-
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', FatalThrowableError::class, \Symfony\Component\ErrorHandler\Exception\ErrorException::class), E_USER_DEPRECATED);
14+
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4.', FatalThrowableError::class), E_USER_DEPRECATED);
1515

1616
/**
1717
* Fatal Throwable Error.
1818
*
1919
* @author Nicolas Grekas <p@tchwork.com>
2020
*
21-
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\Exception\ErrorException instead.
21+
* @deprecated since Symfony 4.4
2222
*/
2323
class FatalThrowableError extends FatalErrorException
2424
{

src/Symfony/Component/ErrorHandler/Exception/ErrorException.php

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy