Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Debug][ErrorHandler] Preserve our error handler when a logger sets another one#29869

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

Conversation

@fancyweb
Copy link
Contributor

@fancywebfancyweb commentedJan 13, 2019
edited
Loading

QA
Branch?3.4
Bug fix?yes
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets-
LicenseMIT
Doc PR-

When logging errors handled by theErrorHandler::handleError() method, the logger can temporarily set its own custom error handler. This is for example the case ofMonolog in theStreamHandler class (cfhttps://github.com/Seldaek/monolog/blob/ebb804e432e8fe0fe96828f30d89c45581d36d07/src/Monolog/Handler/StreamHandler.php#L101).

However, when the previous error handler is restored by the logger, it "skips" the real previous handler (theErrorHandler::handleError() one) in the pile and goes back directly to the one before. I guess this is because therestore_error_handler() call is technically done in the error handler itself, so it logically restore it to the one before and not to itself.

Here is an easy small example that shows the PHP behavior :https://3v4l.org/4OZNZ

The only solution I have found to fix it is to set our error handler everytime an error is logged.

Here are the things I discovered while trying to find a cleaner fix :

  • Setting the same error handler in the error handler itself doesn't actually add it to the pile. This is why adding a check is useless.
  • Checking if the logger modified the error handler is impossible anyway : to get the current error handler, you need to set a new one temporarirly and then revert it. However, when you revert it by callingrestore_error_handler() you end up having the same problem you are trying to fix...
  • Also trying to get the current error handler in the error handler itself will return NULL if it is itself.

@fancywebfancyweb changed the title[Debug][ErrorHandler] Preserve our error handler when a logger set another one[Debug][ErrorHandler] Preserve our error handler when a logger sets another oneJan 13, 2019
@fancywebfancywebforce-pushed thealways-preserve-error-handler-when-logging branch 2 times, most recently from2c73341 to6af95d4CompareJanuary 17, 2019 20:39
@nicolas-grekasnicolas-grekas added this to the3.4 milestoneJan 24, 2019
@nicolas-grekas
Copy link
Member

Nice finding, LGTM. Could you please have a look at HHVM tests, are they related? (rebasing and checking other PRs on 3.4 might help decide).

@fancywebfancywebforce-pushed thealways-preserve-error-handler-when-logging branch from6af95d4 toa40a292CompareJanuary 24, 2019 20:20
@fancywebfancywebforce-pushed thealways-preserve-error-handler-when-logging branch froma40a292 tob979fffCompareJanuary 24, 2019 20:42
@fancyweb
Copy link
ContributorAuthor

Failures were actually related.

Turns out this bug does not exist on the tested HHVM version so we must not readd the error handler.

@nicolas-grekas
Copy link
Member

Good catch, thanks@fancyweb.

@nicolas-grekasnicolas-grekas merged commitb979fff intosymfony:3.4Jan 25, 2019
nicolas-grekas added a commit that referenced this pull requestJan 25, 2019
…gger sets another one (fancyweb)This PR was merged into the 3.4 branch.Discussion----------[Debug][ErrorHandler] Preserve our error handler when a logger sets another one| Q             | A| ------------- | ---| Branch?       | 3.4| Bug fix?      | yes| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets | -| License       | MIT| Doc PR        | -When logging errors handled by the `ErrorHandler::handleError()` method, the logger can temporarily set its own custom error handler. This is for example the case of `Monolog` in the `StreamHandler` class (cfhttps://github.com/Seldaek/monolog/blob/ebb804e432e8fe0fe96828f30d89c45581d36d07/src/Monolog/Handler/StreamHandler.php#L101).However, when the previous error handler is restored by the logger, it "skips" the real previous handler (the `ErrorHandler::handleError()` one) in the pile and goes back directly to the one before. I guess this is because the `restore_error_handler()` call is technically done in the error handler itself, so it logically restore it to the one before and not to itself.Here is an easy small example that shows the PHP behavior :https://3v4l.org/4OZNZThe only solution I have found to fix it is to set our error handler everytime an error is logged.Here are the things I discovered while trying to find a cleaner fix :- Setting the same error handler in the error handler itself doesn't actually add it to the pile. This is why adding a check is useless.- Checking if the logger modified the error handler is impossible anyway : to get the current error handler, you need to set a new one temporarirly and then revert it. However, when you revert it by calling `restore_error_handler()` you end up having the same problem you are trying to fix...- Also trying to get the current error handler in the error handler itself will return NULL if it is itself.Commits-------b979fff [Debug][ErrorHandler] Preserve our error handler when a logger set another one
This was referencedJan 29, 2019
@fancywebfancyweb deleted the always-preserve-error-handler-when-logging branchAugust 9, 2019 07:13
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

3.4

Development

Successfully merging this pull request may close these issues.

3 participants

@fancyweb@nicolas-grekas@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp