Thanks to visit codestin.com
Credit goes to github.com

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

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Nov 9, 2019

Q A
Branch? 4.4
Bug fix? no
New feature? no
Deprecations? yes
Tickets -
License MIT
Doc PR -

Replaces #34232

This PR gets rid of the FatalThrowableError wrapper we introduced when doing the transition from PHP 5 to PHP 7 - to handle all Throwable in a seamless way.

It does so by replacing the kernel.exception event by the kernel.error one. The new name is consistent with the console.error event that we introduced for similar reasons in the Console component.

Along the way, some method/classes are renamed.
The ErrorException class from the ErrorHandler component is removed.

$event = new ExceptionEvent($this, $request, $type, $e);
$this->dispatcher->dispatch($event, KernelEvents::EXCEPTION);
if (!$this->dispatcher instanceof \Symfony\Component\EventDispatcher\EventDispatcherInterface) {
@trigger_error('Listening to the "kernel.exception" event is deprecated since Symfony 4.4, listen to "kernel.error" instead.', E_USER_DEPRECATED);
Copy link
Contributor

Choose a reason for hiding this comment

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

how can affected people get rid of the deprecation?

Copy link
Member Author

@nicolas-grekas nicolas-grekas Nov 9, 2019

Choose a reason for hiding this comment

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

I think we don't have any other alternative here: ppl that hit this code path must bump to v5.
Good news, this affects ppl that implement EventDispatcherInterface from the contracts ONLY (excluding the one from the component). If such an implementation exists (does it?), it must be very new, and very rare.

@nicolas-grekas
Copy link
Member Author

PR is ready.

@Tobion
Copy link
Contributor

Tobion commented Nov 9, 2019

Fine for me. But I don't get why this would be better than #33065 (comment).
This new solution just achieves the same thing but forces a much bigger bc break and many more affected users.

@nicolas-grekas
Copy link
Member Author

nicolas-grekas commented Nov 10, 2019

This new solution just achieves the same thing but forces a much bigger bc break and many more affected users.

In terms of amount of code, renaming the methods on the ExceptionEvent class has a similar impact as renaming the class to ErrorEvent without renaming the methods. Then, this also requires ppl to change the way their classes are registered. We could consider this additional requirement a positive one, as it makes the intent more clear, by requiring an explicit opt-in for the new sub-API.

It's also a matter of target names - which one makes more sense: ExceptionEvent::get/setThrowable() or ErrorEvent::get/setException()?

My personal preference goes for the latter, also because it is consistent with the console.error event and the corresponding ConsoleErrorEvent class.

@nicolas-grekas
Copy link
Member Author

Smaller diff, we're going to prefer #34309

@nicolas-grekas nicolas-grekas deleted the kh-error branch November 10, 2019 09:25
fabpot added a commit that referenced this pull request Nov 10, 2019
… 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants