-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Debug] Support any Throwable object in FlattenException #26528
Conversation
4813746
to
ba00693
Compare
* | ||
* @return static | ||
*/ | ||
public static function create($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
to
9a2cf0c
Compare
public static function create(\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
(see instanceof *ExtensionInterface
checks).
If we really want a flatten error, couldn't it just be a new FlattenError
? 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
to
f2782ad
Compare
I've remove the deprecation of the |
@@ -34,88 +34,94 @@ class FlattenExceptionTest extends TestCase | |||
{ | |||
public function testStatusCode() | |||
{ | |||
$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
to
47b06a7
Compare
All right, the change set should be minimal now. Still, my goal would be to remove the |
{ | ||
$e = new static(); | ||
$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
to
f78a15a
Compare
Status: Needs Review |
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
to
25e5cdf
Compare
The failure on Travis looks unrelated. |
Anything left to do here? |
return static::createFromThrowable($exception, $statusCode, $headers); | ||
} | ||
|
||
public static function createFromThrowable(\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 using new
instead (FlattenException::new()
looks better to 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.
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 7 https://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 between create()
and new()
which looks rather confusing to me. Also, I would not recommend to use keywords as method names even if it currently works.
public function setTraceFromException(\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
to
96c1a6f
Compare
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/A Alternative 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-grekas Commits ------- 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 Error This PR documents symfony/symfony#26528 and fixes #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
Throwable
objects into exceptions when working withFlattenException
.ping @instabledesign @ostrolucky @nicolas-grekas