Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
Add ErrorHandler component#31065
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
42d5a64 to3f9b448CompareSimperfit commentedApr 11, 2019
This is gonna be really nice ! |
3f9b448 to342ee6eComparenicolas-grekas commentedApr 12, 2019
Would it make sense no name the component |
yceruto commentedApr 12, 2019
Does that make me think that we should move |
stof commentedApr 12, 2019
The discussion we had with@fabpot and@nicolas-grekas in Brussels concluded that we should indeed create a new component for error handling. Having the production error handling being a responsibility of a component named debug looks weird, as prod is not in debug mode. |
stof commentedApr 12, 2019
I don't think having an ErrorException class being responsible both for representing the Exception and for rendering it in multiple formats is the right architecture for the component though. This is not extendable at all, and cannot even be configurable (as you cannot instantiate the rendering layer in a place configuring it). To me, we need 3separate things in the component:
And then, the Twig-based HTML error page should ideally become a hook into this renderer layer rather than being a totally separate rendering system. |
yceruto commentedApr 12, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I agree, we should also discuss about BC then, there is a lot of exception classes in Debug component used by these two handlers and we wouldn't want this new component require to |
cb2ac97 to50ec30aCompare50ec30a tocc01b78Compareyceruto commentedApr 12, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Update
Still working on the renderer layer... |
Taluu left a comment
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.
How about being able to support more formats ? Wouldn't it be better to have some sort of factory so that we can use whatever format we want ?
Uh oh!
There was an error while loading.Please reload this page.
cc01b78 to8d641e3Compareyceruto commentedApr 12, 2019
Thanks@Taluu for your input, yes I'm working on it. |
8d641e3 toa82888eCompareyceruto commentedApr 14, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Update
interface ErrorRendererInterface{/** * Gets the format of the content. * * @return string The content format */publicstaticfunctiongetFormat():string;/** * Renders an Exception and returns the Response content. * * @return string The Response content as a string */publicfunctionrender(FlattenException$exception):string;}
|
yceruto commentedApr 14, 2019
There are many changes (a big diff), most are movements + deprecations, so I prefer to leave this last issue for another PR |
ed3480a to3c05010Compareyceruto commentedApr 14, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
The PR app demo is ready:https://github.com/yceruto/error-handler-app (add custom error renderer) |
fabpot commentedJun 27, 2019
Thank you@yceruto. |
This PR was merged into the 4.4 branch.Discussion----------Add ErrorHandler component| Q | A| ------------- | ---| Branch? | 4.4| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | yes| Tests pass? | no| Fixed tickets |#25905,#26448| License | MIT| Doc PR | TODOMainly for API-based apps that don't require TwigBundle to get the correct exception response according to the request format (aka `_format` attribute).:heavy_check_mark: [RFC7807](https://tools.ietf.org/html/rfc7807) compliant for JSON and XML formats.---This introduce a new `ErrorRenderer` service that render a `FlattenException` into a given format:```phpuse Symfony\Component\ErrorHandler\ErrorRenderer\ErrorRenderer;use Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer;use Symfony\Component\ErrorHandler\ErrorRenderer\JsonErrorRenderer;$renderers = [ new HtmlErrorRenderer(), new JsonErrorRenderer(), // ...];$errorRenderer = new ErrorRenderer($renderers);return new Response( $errorRenderer->render($exception, $request->getRequestFormat()), $exception->getStatusCode(), $exception->getHeaders());```The built-in error renderers are:| Format | Class || --- | --- || html | HtmlErrorRenderer || json | JsonErrorRenderer || xml, atom | XmlErrorRenderer || txt | TxtErrorRenderer |And you can add your own error renderer by implementing the `ErrorRendererInterface` and tagging it with `error_handler.renderer` in your service definition.Creating your own error renderer for a built-in format will end up replacing the related built-in error renderer.Demo:https://github.com/yceruto/error-handler-app ([add custom error renderer](yceruto/error-handler-app@06fc647))Commits-------7057244 Added ErrorHandler component
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
driesvints commentedJul 4, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@fabpot@yceruto the removed public methods like These changes will, for example break Lumen:laravel/lumen-framework#935 |
Tobion commentedJul 4, 2019
please open a new issue |
driesvints commentedJul 4, 2019
…(1st step) (yceruto)This PR was squashed before being merged into the 4.4 branch (closes#32377).Discussion----------[Debug] Restoring back the state of the Debug component (1st step)| Q | A| ------------- | ---| Branch? | 4.4| Bug fix? | yes| New feature? | no| BC breaks? | no| Deprecations? | yes| Tests pass? | yes| Fixed tickets |#32371| License | MITAfter a good discussion with@nicolas-grekas, we made the decision to split the current `ErrorCatcher` component into several: * `ErrorHandler` it would be the Debug component before these changes#31065, with everything related to ErrorHandler, Debug, DebugClassLoader classes and change its name. * `ErrorDumper` it would be the current ErrorCatcher but with FlattenException + the new error renderer system only.This is the first step, then we can deprecate everything for the Debug component in favor of the ErrorHandler and ErrorDumper components, **BUT without moving any code !!**, that would give us more freedom to do it correctly in the new components.NOTE: For this PR I've copy the `Debug` component directory from the revision prior to merged commit#31065 in 4.4 branch.Commits-------eda49e2 [Debug] Restoring back the state of the Debug component (1st step)
…(1st step) (yceruto)This PR was squashed before being merged into the 4.4 branch (closes #32377).Discussion----------[Debug] Restoring back the state of the Debug component (1st step)| Q | A| ------------- | ---| Branch? | 4.4| Bug fix? | yes| New feature? | no| BC breaks? | no| Deprecations? | yes| Tests pass? | yes| Fixed tickets |symfony/symfony#32371| License | MITAfter a good discussion with@nicolas-grekas, we made the decision to split the current `ErrorCatcher` component into several: * `ErrorHandler` it would be the Debug component before these changessymfony/symfony#31065, with everything related to ErrorHandler, Debug, DebugClassLoader classes and change its name. * `ErrorDumper` it would be the current ErrorCatcher but with FlattenException + the new error renderer system only.This is the first step, then we can deprecate everything for the Debug component in favor of the ErrorHandler and ErrorDumper components, **BUT without moving any code !!**, that would give us more freedom to do it correctly in the new components.NOTE: For this PR I've copy the `Debug` component directory from the revision prior to merged commitsymfony/symfony#31065 in 4.4 branch.Commits-------eda49e295e [Debug] Restoring back the state of the Debug component (1st step)
Uh oh!
There was an error while loading.Please reload this page.
…formats and using ErrorRenderer as fallback (yceruto)This PR was merged into the 4.4 branch.Discussion----------[TwigBundle] Deprecating error templates for non-html formats and using ErrorRenderer as fallback| Q | A| ------------- | ---| Branch? | 4.4| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | yes| Tests pass? | yes| Fixed tickets | -| License | MIT| Doc PR | -In the previous [PR](#31065) we created a new mechanism to render any PHP error/exception in a formatted string, which if the FB is enabled, would return an HTTP Response according to the preferred Request format (html, json, xml, txt, etc.), but when installing the TwigBundle this rendering mechanism is replaced by the current ExceptionController.This ExceptionController allows us to render custom error pages based on Twig in many formats, just what is already supported with the new ErrorRenderer component, so let's deprecate this in favor of the native.Commits-------bf0c24a Deprecating error templates for non-html formats and using ErrorRenderer
ghost commentedDec 7, 2019 • edited by ghost
Loading Uh oh!
There was an error while loading.Please reload this page.
edited by ghost
Uh oh!
There was an error while loading.Please reload this page.
|
Uh oh!
There was an error while loading.Please reload this page.
Mainly for API-based apps that don't require TwigBundle to get the correct exception response according to the request format (aka
_formatattribute).✔️RFC7807 compliant for JSON and XML formats.
This introduce a new
ErrorRendererservice that render aFlattenExceptioninto a given format:The built-in error renderers are:
And you can add your own error renderer by implementing the
ErrorRendererInterfaceand tagging it witherror_handler.rendererin your service definition.Creating your own error renderer for a built-in format will end up replacing the related built-in error renderer.
Demo:https://github.com/yceruto/error-handler-app (add custom error renderer)