Skip to content

[HttpKernel] rename ExceptionEvent to ErrorEvent and remove the ErrorException wrapper #34306

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions UPGRADE-4.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Console
* Deprecated returning `null` from `Command::execute()`, return `0` instead
* Deprecated the `Application::renderException()` and `Application::doRenderException()` methods,
use `renderThrowable()` and `doRenderThrowable()` instead.
* Deprecated `ConsoleErrorEvent::getError()/setError()`, use `getException()/setException()` instead

Debug
-----
Expand Down Expand Up @@ -154,6 +155,12 @@ HttpKernel
* Marked the `RouterDataCollector::collect()` method as `@final`.
* The `DataCollectorInterface::collect()` and `Profiler::collect()` methods third parameter signature
will be `\Throwable $exception = null` instead of `\Exception $exception = null` in Symfony 5.0.
* Deprecated class `ExceptionEvent`, use `ErrorEvent` instead
* Deprecated class `ExceptionListener`, use `ErrorListener` instead
* Deprecated constant `KernelEvents::EXCEPTION`, use `KernelEvents::ERROR` instead
* Deprecated event `kernel.exception`, listen to `kernel.error` instead
* Deprecated method `ProfilerListener::onKernelException()`, use `onKernelError()` instead
* Deprecated method `RouterListener::onKernelException()`, use `onKernelError()` instead

Lock
----
Expand Down Expand Up @@ -212,6 +219,7 @@ Security
* The `LdapUserProvider` class has been deprecated, use `Symfony\Component\Ldap\Security\LdapUserProvider` instead.
* Implementations of `PasswordEncoderInterface` and `UserPasswordEncoderInterface` should add a new `needsRehash()` method
* Deprecated returning a non-boolean value when implementing `Guard\AuthenticatorInterface::checkCredentials()`. Please explicitly return `false` to indicate invalid credentials.
* Deprecated method `ExceptionListener::onKernelException()`, use `onKernelError()` instead
* Deprecated passing more than one attribute to `AccessDecisionManager::decide()` and `AuthorizationChecker::isGranted()` (and indirectly the `is_granted()` Twig and ExpressionLanguage function)

**Before**
Expand Down
8 changes: 8 additions & 0 deletions UPGRADE-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Console
* Removed the `setVerticalBorderChar()` method in favor of the `setVerticalBorderChars()` method in `TableStyle`.
* Removed the `getVerticalBorderChar()` method in favor of the `getBorderChars()` method in `TableStyle`.
* Removed support for returning `null` from `Command::execute()`, return `0` instead
* Removed `ConsoleErrorEvent::getError()/setError()`, use `getException()/setException()` instead
* The `ProcessHelper::run()` method takes the command as an array of arguments.

Before:
Expand Down Expand Up @@ -290,6 +291,12 @@ HttpKernel
* Removed `TranslatorListener` in favor of `LocaleAwareListener`
* The `DebugHandlersListener` class has been made `final`
* Removed `SaveSessionListener` in favor of `AbstractSessionListener`
* Removed class `ExceptionEvent`, use `ErrorEvent` instead
* Removed class `ExceptionListener`, use `ErrorListener` instead
* Removed constant `KernelEvents::EXCEPTION`, use `KernelEvents::ERROR` instead
* Removed event `kernel.exception`, listen to `kernel.error` instead
* Removed method `ProfilerListener::onKernelException()`, use `onKernelError()` instead
* Removed method `RouterListener::onKernelException()`, use `onKernelError()` instead
* Added new Bundle directory convention consistent with standard skeletons:

```
Expand Down Expand Up @@ -470,6 +477,7 @@ Security
* Classes implementing the `TokenInterface` must implement the two new methods
`__serialize` and `__unserialize`
* Implementations of `Guard\AuthenticatorInterface::checkCredentials()` must return a boolean value now. Please explicitly return `false` to indicate invalid credentials.
* Removed method `ExceptionListener::onKernelException()`, use `onKernelError()` instead

SecurityBundle
--------------
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bundle/FrameworkBundle/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Debug\Exception\FatalThrowableError;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\ErrorHandler\Exception\ErrorException;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\HttpKernel\KernelInterface;
Expand Down Expand Up @@ -211,7 +211,7 @@ private function renderRegistrationErrors(InputInterface $input, OutputInterface
$this->doRenderThrowable($error, $output);
} else {
if (!$error instanceof \Exception) {
$error = new ErrorException($error);
$error = new FatalThrowableError($error);
}

$this->doRenderException($error, $output);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ final class SuggestMissingPackageSubscriber implements EventSubscriberInterface

public function onConsoleError(ConsoleErrorEvent $event): void
{
if (!$event->getError() instanceof CommandNotFoundException) {
if (!$event->getException() instanceof CommandNotFoundException) {
return;
}

Expand All @@ -64,14 +64,14 @@ public function onConsoleError(ConsoleErrorEvent $event): void
$exact = false;
}

$error = $event->getError();
$error = $event->getException();

if ($error->getAlternatives() && !$exact) {
return;
}

$message = sprintf("%s\n\nYou may be looking for a command provided by the \"%s\" which is currently not installed. Try running \"composer require %s\".", $error->getMessage(), $suggestion[0], $suggestion[1]);
$event->setError(new CommandNotFoundException($message));
$event->setException(new CommandNotFoundException($message));
}

public static function getSubscribedEvents(): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<parameter key="Symfony\Component\HttpKernel\Event\FinishRequestEvent">kernel.finish_request</parameter>
<parameter key="Symfony\Component\HttpKernel\Event\RequestEvent">kernel.request</parameter>
<parameter key="Symfony\Component\HttpKernel\Event\ViewEvent">kernel.view</parameter>
<parameter key="Symfony\Component\HttpKernel\Event\ErrorEvent">kernel.error</parameter>
<parameter key="Symfony\Component\HttpKernel\Event\ExceptionEvent">kernel.exception</parameter>
<parameter key="Symfony\Component\HttpKernel\Event\TerminateEvent">kernel.terminate</parameter>
<parameter key="Symfony\Component\Workflow\Event\GuardEvent">workflow.guard</parameter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
<argument type="service" id="error_renderer" />
</service>

<service id="exception_listener" class="Symfony\Component\HttpKernel\EventListener\ExceptionListener">
<service id="exception_listener" class="Symfony\Component\HttpKernel\EventListener\ErrorListener">
<tag name="kernel.event_subscriber" />
<tag name="monolog.logger" channel="request" />
<argument>%kernel.error_controller%</argument>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ private function createEventForSuggestingPackages(string $command, array $altern
$subscriber = new SuggestMissingPackageSubscriber();
$subscriber->onConsoleError($event);

return $event->getError()->getMessage();
return $event->getException()->getMessage();
}

private function getKernel(array $bundles, $useDispatcher = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
public static function getSubscribedEvents(): array
{
return [
KernelEvents::EXCEPTION => 'onKernelException',
KernelEvents::ERROR => 'onKernelException',
];
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bundle/FrameworkBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"paragonie/sodium_compat": "^1.8",
"symfony/asset": "^3.4|^4.0|^5.0",
"symfony/browser-kit": "^4.3|^5.0",
"symfony/console": "^4.3.4|^5.0",
"symfony/console": "^4.4|^5.0",
"symfony/css-selector": "^3.4|^4.0|^5.0",
"symfony/dom-crawler": "^4.3|^5.0",
"symfony/dotenv": "^4.3.6|^5.0",
Expand Down Expand Up @@ -70,7 +70,7 @@
"phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0",
"symfony/asset": "<3.4",
"symfony/browser-kit": "<4.3",
"symfony/console": "<4.3",
"symfony/console": "<4.4",
"symfony/dotenv": "<4.3.6",
"symfony/dom-crawler": "<4.3",
"symfony/http-client": "<4.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function previewErrorPageAction(Request $request, $code)

/*
* This Request mimics the parameters set by
* \Symfony\Component\HttpKernel\EventListener\ExceptionListener::duplicateRequest, with
* \Symfony\Component\HttpKernel\EventListener\ErrorListener::duplicateRequest, with
* the additional "showException" flag.
*/

Expand Down
11 changes: 5 additions & 6 deletions src/Symfony/Component/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Debug\ErrorHandler as LegacyErrorHandler;
use Symfony\Component\Debug\Exception\FatalThrowableError as LegacyFatalThrowableError;
use Symfony\Component\Debug\Exception\FatalThrowableError;
use Symfony\Component\ErrorHandler\ErrorHandler;
use Symfony\Component\ErrorHandler\Exception\ErrorException;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
use Symfony\Contracts\Service\ResetInterface;
Expand Down Expand Up @@ -245,7 +244,7 @@ public function doRun(InputInterface $input, OutputInterface $output)
return 0;
}

$e = $event->getError();
$e = $event->getException();
}

throw $e;
Expand Down Expand Up @@ -809,7 +808,7 @@ public function renderThrowable(\Throwable $e, OutputInterface $output): void
@trigger_error(sprintf('The "%s::renderException()" method is deprecated since Symfony 4.4, use "renderThrowable()" instead.', __CLASS__), E_USER_DEPRECATED);

if (!$e instanceof \Exception) {
$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()));
$e = class_exists(FatalThrowableError::class) ? new FatalThrowableError($e) : new \ErrorException($e->getMessage(), $e->getCode(), E_ERROR, $e->getFile(), $e->getLine());
}

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

if (!$e instanceof \Exception) {
$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()));
$e = class_exists(FatalThrowableError::class) ? new FatalThrowableError($e) : new \ErrorException($e->getMessage(), $e->getCode(), E_ERROR, $e->getFile(), $e->getLine());
}

$this->doRenderException($e, $output);
Expand Down Expand Up @@ -1034,7 +1033,7 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
} catch (\Throwable $e) {
$event = new ConsoleErrorEvent($input, $output, $e, $command);
$this->dispatcher->dispatch($event, ConsoleEvents::ERROR);
$e = $event->getError();
$e = $event->getException();

if (0 === $exitCode = $event->getExitCode()) {
$e = null;
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Console/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ CHANGELOG
* Deprecated the `Application::renderException()` and `Application::doRenderException()` methods,
use `renderThrowable()` and `doRenderThrowable()` instead.
* added support for the `NO_COLOR` env var (https://no-color.org/)
* deprecated `ConsoleErrorEvent::getError()/setError()`, use `getException()/setException()` instead

4.3.0
-----
Expand Down
38 changes: 29 additions & 9 deletions src/Symfony/Component/Console/Event/ConsoleErrorEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,57 @@
*/
final class ConsoleErrorEvent extends ConsoleEvent
{
private $error;
private $exception;
private $exitCode;

public function __construct(InputInterface $input, OutputInterface $output, \Throwable $error, Command $command = null)
public function __construct(InputInterface $input, OutputInterface $output, \Throwable $exception, Command $command = null)
{
parent::__construct($command, $input, $output);

$this->error = $error;
$this->exception = $exception;
}

public function getException(): \Throwable
{
return $this->exception;
}

public function setException(\Throwable $exception): void
{
$this->exception = $exception;
}

/**
* @deprecated since Symfony 4.4, use getException() instead
*/
public function getError(): \Throwable
{
return $this->error;
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.4, use "getException()" instead.', __METHOD__), E_USER_DEPRECATED);

return $this->exception;
}

public function setError(\Throwable $error): void
/**
* @deprecated since Symfony 4.4, use setException() instead
*/
public function setError(\Throwable $exception): void
{
$this->error = $error;
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.4, use "setException()" instead.', __METHOD__), E_USER_DEPRECATED);

$this->exception = $exception;
}

public function setExitCode(int $exitCode): void
{
$this->exitCode = $exitCode;

$r = new \ReflectionProperty($this->error, 'code');
$r = new \ReflectionProperty($this->exception, 'code');
$r->setAccessible(true);
$r->setValue($this->error, $this->exitCode);
$r->setValue($this->exception, $this->exitCode);
}

public function getExitCode(): int
{
return null !== $this->exitCode ? $this->exitCode : (\is_int($this->error->getCode()) && 0 !== $this->error->getCode() ? $this->error->getCode() : 1);
return null !== $this->exitCode ? $this->exitCode : (\is_int($this->exception->getCode()) && 0 !== $this->exception->getCode() ? $this->exception->getCode() : 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function onConsoleError(ConsoleErrorEvent $event)
return;
}

$error = $event->getError();
$error = $event->getException();

if (!$inputString = $this->getInputString($event)) {
$this->logger->error('An error occurred while using the console. Message: "{message}"', ['exception' => $error, 'message' => $error->getMessage()]);
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Console/Tests/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1438,7 +1438,7 @@ public function testConsoleErrorEventIsTriggeredOnCommandNotFound()
$dispatcher = new EventDispatcher();
$dispatcher->addListener('console.error', function (ConsoleErrorEvent $event) {
$this->assertNull($event->getCommand());
$this->assertInstanceOf(CommandNotFoundException::class, $event->getError());
$this->assertInstanceOf(CommandNotFoundException::class, $event->getException());
$event->getOutput()->write('silenced command not found');
});

Expand Down Expand Up @@ -1727,7 +1727,7 @@ protected function getDispatcher($skipCommand = false)
$dispatcher->addListener('console.error', function (ConsoleErrorEvent $event) {
$event->getOutput()->write('error.');

$event->setError(new \LogicException('error.', $event->getExitCode(), $event->getError()));
$event->setException(new \LogicException('error.', $event->getExitCode(), $event->getException()));
});

return $dispatcher;
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Debug/Exception/FatalErrorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

namespace Symfony\Component\Debug\Exception;

@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);
@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);

/**
* Fatal Error Exception.
*
* @author Konstanton Myakshin <koc-dp@yandex.ru>
*
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\Exception\ErrorException instead.
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\Error\FatalError instead.
*/
class FatalErrorException extends \ErrorException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@

namespace Symfony\Component\Debug\Exception;

@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);
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4.', FatalThrowableError::class), E_USER_DEPRECATED);

/**
* Fatal Throwable Error.
*
* @author Nicolas Grekas <p@tchwork.com>
*
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\Exception\ErrorException instead.
*/
class FatalThrowableError extends FatalErrorException
{
Expand Down
42 changes: 0 additions & 42 deletions src/Symfony/Component/ErrorHandler/Exception/ErrorException.php

This file was deleted.

Loading