-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Console] Give errors back to error handler if not handled by console.error listeners #22261
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
BC bug fixes should have a unit test to ensure the issue will not surface again. |
Yeah, I didn't find a relevant way to test this yet. |
Sure, it'll fix the BC break. Thank you for creating the issue and for this PR. 😃 In #20808 however, I also wanted to add support for handling errors natively & easily with the standalone component, when you don't use an error handler like the one in the Debug component. Regarding the test, why not just testing the error is properly re-thrown by Application? You don't need to test an error handler is called. |
20c4419
to
903ea95
Compare
…e.error listeners
903ea95
to
5a5bf54
Compare
Test added, I was missing something.
As discussed together, I think we can first merge this as is in order to fix the introduced BC break and improve the situation in a next time but indeed, having a default error handler in the console seems like a good compromise to me. PR ready, build failures unrelated. |
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 please note that I'm going to look at error handling in console a bit more deeply during feat freeze. I may change a few things to what #18140 did.
Thank you @chalasr. |
… by console.error listeners (chalasr) This PR was merged into the 3.3-dev branch. Discussion ---------- [Console] Give errors back to error handler if not handled by console.error listeners | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #22259 | License | MIT | Doc PR | n/a Re-throws errors if `ConsoleErrorEvent::markErrorAsHandled()` hasn't been called so that they can reach the global error handler, fixing the BC break. Commits ------- 5a5bf54 [Console] Give errors back to error handlers if not handled by console.error listeners
@nicolas-grekas One thing to note is that errors are still not rethrown in case the application has no event dispatcher (occurs only using the component independently), even after this. I just realize it and was going to look into but I'll wait then, don't hesitate to ping me for a hand. |
@@ -138,6 +138,9 @@ public function run(InputInterface $input = null, OutputInterface $output = null | ||
$e = null; | ||
$exitCode = 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.
technically, the debug handler handles the exception (rendering it in a special way), but could still want to use a failure exit code. We should let the event change the code.
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.
Yes, that's the conclusion we came to with @chalasr regarding this part. I guess now it's better to wait for a PR with a bigger vision of the remaining issues with the component, as @nicolas-grekas seems to plan.
…onsole.error listeners (chalasr) This PR was merged into the 2.7 branch. Discussion ---------- [Console] Fix errors not rethrown even if not handled by console.error listeners | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #22678 | License | MIT | Doc PR | n/a #22261 has been squashed while revisiting error handling, this fixes it again while keeping latest changes intact. __code__ ```php public function execute(InputInterface $input, OutputInterface $output) { $this->barr(); } public function bar() { } ``` __before__  __after__  Commits ------- 75f098f Fix errors not rethrown even if not handled by console.error listeners
Re-throws errors if
ConsoleErrorEvent::markErrorAsHandled()
hasn't been called so that they can reach the global error handler, fixing the BC break.