-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Debug] Better error handling #19568
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
Conversation
c17f213
to
64b6a4e
Compare
816e296
to
29cb0a7
Compare
@@ -373,24 +376,28 @@ public function handleError($type, $message, $file, $line, array $context, array | |||
if (null !== $backtrace && $type & E_ERROR) { | |||
// E_ERROR fatal errors are triggered on HHVM when | |||
// hhvm.error_handling.call_user_handler_on_fatals=1 | |||
// which is the way to get their backtrace. | |||
// which is the way to get their backtraces. |
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.
Previous sounds correct to me.
4d60d08
to
335f47b
Compare
Status: Needs review |
Looks like a really nice improvement to me. 👍 |
{% if stack %} | ||
<button class="btn-link text-small sf-toggle" data-toggle-selector="#{{ stack_id }}" data-toggle-alt-content="Hide stack trace">Show stack trace</button> | ||
{% if trace %} | ||
<button class="btn-link text-small sf-toggle" data-toggle-selector="#{{ trace_id }}" data-toggle-alt-content="Hide trace trace">Show trace trace</button> |
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.
Show trace / Hide trace, right ?
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.
Good catch. Thanks.
335f47b
to
f19fe82
Compare
Unless someone would like to review this PR and needs more time, I plan to merge this one by the end of the day. |
👍 |
I understand the need for the |
The For the record, I did not add the |
For For |
I think we can drop |
Yes, we can not change the value of log to true as it's a kind of BC. I'm gonna remove the 2 others options. |
f19fe82
to
89feb7f
Compare
->booleanNode('log') | ||
->info('Use the app logger instead of the PHP logger for logging PHP errors.') | ||
->defaultValue($this->debug) | ||
->treatNullLike($this->debug) |
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 don't understand the default value. For me, the value does not depend on the debug flag. It should be true
by default (most sensible value) and devs can switch it to false
to keep BC. But then, what about having this as a temporary setting to keep BC that needs to be removed in 4.0?
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.
But then, what about having this as a temporary setting to keep BC that needs to be removed in 4.0?
👍 It was ou initial idea.
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 added a deprecation notice.
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.
And I reverted it. I cause too many troubles with tests that can not be fixed.
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 reverted the deprecation, but the value is still at debug, which looks very wrong to me still.
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.
the value is now false
.
20585ae
to
8829998
Compare
1. Send the raw exception in the log context instead of custom formatting 2. Add config option to log in Symfony all PHP errors
8829998
to
8f24549
Compare
Thank you @lyrixx. |
This PR was merged into the 3.2-dev branch. Discussion ---------- [Debug] Better error handling | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | - | Fixed tickets | - | License | MIT | Doc PR | symfony/symfony-docs#6870 1. Send the raw exception in the log context instead of custom formatting 2. Add config option to log/throw in Symfony all PHP errors 3. Always use an exception when a PHP error occurs 4. Expand exception in the log context in the web developer toolbar 5. Use the dumper to dump log context in the web developer toolbar --- I used the following code to produce screenshots: ```php public function indexAction(Request $request) { $this->get('logger')->info('A log message with an exception', ['exception' => new \Exception('this exception will be logged')]); error_reporting(0); for ($i=0; $i < 15; $i++) { if ($i == 5) { error_reporting(E_ALL); } if ($i == 10) { error_reporting(0); } trigger_error("Trigger error avec E_USER_NOTICE", E_USER_NOTICE); } error_reporting(E_ALL); @trigger_error("trigger_error avec E_USER_DEPRECATED", E_USER_DEPRECATED); trigger_error("trigger_error avec E_USER_DEPRECATED (not silent)", E_USER_DEPRECATED); // ... ```    Commits ------- 8f24549 [Debug] Better error handling
This PR was merged into the 3.2-dev branch. Discussion ---------- Log all PHP errors with the default logger related to symfony/symfony#19568 Commits ------- ba48afe Log all PHP errors with the default logger
… of traces (nicolas-grekas) This PR was merged into the 3.2-dev branch. Discussion ---------- [FrameworkBundle][Debug] Fix default config and cleaning of traces | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | Tests pass? | yes | Fixed tickets | Follow up #19568 | License | MIT | Doc PR | - The default value of `framework.php_errors.log` must be `%kernel.debug%` to have deprecations and silenced errors logged in dev as before. Cleaning the trace was broken because a closure can't be bound to an internal class. This PR fixes both issues and enhance trace cleaning a bit by removing arguments from traces so that they take less memory when collected as part of the context of log messages. Commits ------- f640870 [FrameworkBundle][Debug] Fix default config and cleaning of traces
* | ||
* @author Grégoire Pineau <lyrixx@lyrixx.info> | ||
*/ | ||
class SilencedErrorContext implements \JsonSerializable |
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 don't recall, why is it JsonSerializable
? (cc @nicolas-grekas)?
It does not play well with monolog:
https://github.com/Seldaek/monolog/blob/b05bf55097060ec20f49ccec0cf2f8e5aaa468b3/src/Monolog/Formatter/NormalizerFormatter.php#L195-L197
I got this in my index:
{
"_index": "monolog",
"_type": "_doc",
"_id": "sU9quogBWJfLYe0zo1VX",
"_score": 1,
"fields": {
"context.exception.Symfony\\Component\\ErrorHandler\\Exception\\SilencedErrorContext.trace.type.keyword": [
"->"
],
"context.exception.Symfony\\Component\\ErrorHandler\\Exception\\SilencedErrorContext.trace.class.keyword": [
"Symfony\\Component\\ErrorHandler\\ErrorHandler"
],
"context.exception.Symfony\\Component\\ErrorHandler\\Exception\\SilencedErrorContext.trace.class": [
"Symfony\\Component\\ErrorHandler\\ErrorHandler"
],
"context.exception.Symfony\\Component\\ErrorHandler\\Exception\\SilencedErrorContext.trace.function": [
"handleError"
],
"context.exception.Symfony\\Component\\ErrorHandler\\Exception\\SilencedErrorContext.trace.function.keyword": [
"handleError"
],
"context.exception.Symfony\\Component\\ErrorHandler\\Exception\\SilencedErrorContext.trace.type": [
"->"
],
"context.exception.Symfony\\Component\\ErrorHandler\\Exception\\SilencedErrorContext.count": [
1
],
"context.exception.Symfony\\Component\\ErrorHandler\\Exception\\SilencedErrorContext.severity": [
2
],
"context.exception.Symfony\\Component\\ErrorHandler\\Exception\\SilencedErrorContext.file.keyword": [
"Unknown"
],
"context.exception.Symfony\\Component\\ErrorHandler\\Exception\\SilencedErrorContext.line": [
0
],
"context.exception.Symfony\\Component\\ErrorHandler\\Exception\\SilencedErrorContext.file": [
"Unknown"
]
}
}
I used the following code to produce screenshots: