Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Debug] Support any Throwable object in FlattenException#26528
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
4813746 toba00693Compare| * | ||
| * @return static | ||
| */ | ||
| publicstaticfunctioncreate($throwable,$statusCode =null,array$headers =array()) |
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.
your#26447 (comment) comment applies as well, removing a typehint breaks childs
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.
You're right, it will raise a warning. I'll add another deprecation then.
10cef07 to9a2cf0cCompare| */ | ||
| publicstaticfunctioncreate(\Exception$exception,$statusCode =null,array$headers =array()) | ||
| { | ||
| @trigger_error(sprintf('"%s" is deprecated since Symfony 4.1. Use "createFromThrowable()" instead.',__METHOD__),E_USER_DEPRECATED); |
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.
maybe we should not deprecate this method and save us the version bumps?
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.
a lot of code in this class will never be reached in case the throwable is an\Error (seeinstanceof *ExtensionInterface checks).
If we really want a flatten error, couldn't it just be a newFlattenError? extracting the reusable logic in a trait if any
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.
Tbh, given the error handling in place I fear that anyways the result will be more confusing than useful here, perhaps it's just me
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.
👍 for FlattenError
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.
I did not expect those version bumps to be a problem, but we can add the depreciation at a later point, I guess. I'm going to remove the deprecation an revert the changes I made to other components.
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.
If I added a separate class for errors, I would need to duplicate a lot of code, lose the ability to properly type-hint for FlattenException and I'd still have to do type-switches when working with arbitrary throwables. Sorry, but this is really a bad idea, imho.
9a2cf0c tof2782adComparederrabus commentedMar 15, 2018
I've remove the deprecation of the |
| publicfunctiontestStatusCode() | ||
| { | ||
| $flattened = FlattenException::create(new \RuntimeException(),403); | ||
| $flattened = FlattenException::createFromThrowable(new \RuntimeException(),403); |
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.
unless required, these changes should also be reverted, this will help merges as usual
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.
Understandable, although I'd prefer to keep the test as it is. I'll change it.
4fdb120 to47b06a7Comparederrabus commentedMar 15, 2018
All right, the change set should be minimal now. Still, my goal would be to remove the |
| publicstaticfunctioncreateFromThrowable(\Throwable$throwable, ?int$statusCode =null,array$headers =array()):self | ||
| { | ||
| $e =newstatic(); | ||
| $e->setMessage($exception->getMessage()); |
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.
sorry, anynother change: let's keep the old name, it's still fine
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.
Fair enough.
47b06a7 tof78a15aComparederrabus commentedMar 16, 2018
Status: Needs Review |
instabledesign 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.
Sounds good.
f78a15a to25e5cdfComparederrabus commentedMar 16, 2018
The failure on Travis looks unrelated. |
derrabus commentedMar 19, 2018
Anything left to do here? |
| returnstatic::createFromThrowable($exception,$statusCode,$headers); | ||
| } | ||
| publicstaticfunctioncreateFromThrowable(\Throwable$exception, ?int$statusCode =null,array$headers =array()):self |
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.
What about usingnew instead (FlattenException::new() looks better to me)?
nicolas-grekasApr 2, 2018 • 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.
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.
it's not possible to call a function "new" because the keyword is reserved...
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.
Works in php 7https://3v4l.org/N5iEr
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.
Well, then the developer would have the choice betweencreate() andnew() which looks rather confusing to me. Also, I would not recommend to use keywords as method names even if it currently works.
| publicfunctionsetTraceFromException(\Exception$exception) | ||
| { | ||
| $this->setTrace($exception->getTrace(),$exception->getFile(),$exception->getLine()); | ||
| @trigger_error(sprintf('"%s" is deprecated since Symfony 4.1. Use "setTraceFromThrowable()" instead.',__METHOD__),E_USER_DEPRECATED); |
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.
should be... since Symfony 4.1, use ...
25e5cdf to96c1a6fComparefabpot commentedApr 6, 2018
Thank you@derrabus. |
…on (derrabus)This PR was merged into the 4.1-dev branch.Discussion----------[Debug] Support any Throwable object in FlattenException| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | yes| Tests pass? | yes| Fixed tickets |#26429| License | MIT| Doc PR | N/AAlternative to#26447 without BC breaks, follows#26028.This PR removes the need to convert `Throwable` objects into exceptions when working with `FlattenException`.ping@instabledesign@ostrolucky@nicolas-grekasCommits-------96c1a6f Support any Throwable object in FlattenException.
…r (derrabus)This PR was merged into the master branch.Discussion----------FlattenException might also represent an instance of ErrorThis PR documentssymfony/symfony#26528 andfixes#9636.Commits-------cd309c9 FlattenException might also represent an instance of Error.
Alternative to#26447 without BC breaks, follows#26028.
This PR removes the need to convert
Throwableobjects into exceptions when working withFlattenException.ping@instabledesign@ostrolucky@nicolas-grekas