8000 [Console] Fix restoring exception handler by nicolas-grekas · Pull Request #25753 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Console] Fix restoring exception handler #25753

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

Merged
merged 2 commits into from
Jan 16, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[Console] Fix restoring exception handler
  • Loading branch information
nicolas-grekas committed Jan 16, 2018
commit 3fa1ad9c81c96b826da5973883fce204e5389973
5 changes: 5 additions & 0 deletions src/Symfony/Component/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,12 @@ public function run(InputInterface $input = null, OutputInterface $output = null
$exitCode = 1;
}
} finally {
// if the exception handler changed, keep it
// otherwise, unregister $renderException
if (!$phpHandler) {
if (set_exception_handler($renderException) === $renderException) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @dbu to either add comments or extract some private methods. Also I don't get how this solves the problem. From how I understood #25718, the Kernel exception handler is set after the console one. So set_exception_handler($renderException) === $renderException is not true. And even if it is true, this block only sets an exception handler that is then removed again?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the code is correct. The only way to learn the current handler is to overwrite it. If condition is true, we pop it out again. Then either way we pop one more time. If condition was true, that removes the actual handler, otherwise it pops the thing we set to learn what handler was set.

restore_exception_handler();
}
restore_exception_handler();
} elseif (!$debugHandler) {
$phpHandler[0]->setExceptionHandler(null);
Expand Down
0