-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[Console] add support for catching \Throwable errors
#50420
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
| Q | A |
|---|---|
| Branch? | 6.4 |
| Bug fix? | no |
| New feature? | yes |
| Deprecations? | no |
| Tickets | Fix #46596 |
| License | MIT |
| Doc PR |
|
Historical question: were all the |
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.
LGTM
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 broken test covers the behavior for which we cannot just do this unfortunately. Check #22690 for background (tldr errors must keep reaching custom error handlers).
|
Hmm, When using the component directly without the error handler, a command can crash badly :/ What about adding a flag to choose if we should handle throwable or not? |
|
Sounds like a good idea 👍 |
|
The very lines before the try/catch setup a global error/exception handler, why does this crash badly as you write, while we have this in place? |
|
@nicolas-grekas let's say you are building a project that run commands, when someone makes an error in the command, it will produces theses outputs: Without this patch:With this patch (there is color, and Symfony styling):And if the developer wants more output, they can run the same command with |
|
Very simple reproducer : take only symfony/console, then run: <?php
require __DIR__.'/vendor/autoload.php';
use Symfony\Component\Console\SingleCommandApplication;
(new SingleCommandApplication())
->setCode(function () {
echo "AAA";
foobar();
})
->run()
; |
aeac386 to
83417ea
Compare
|
I have rebased the PR, restored BC, added a new flag to handle errors, and added some tests. I think it's ready ✅ |
83417ea to
8fc6dd2
Compare
\Throwable exceptions\Throwable errors
8fc6dd2 to
0c2552e
Compare
0c2552e to
7a35645
Compare
7a35645 to
1baeb3d
Compare
|
Thank you @lyrixx. |
|
@Seldaek FYI |
|
@chalasr thanks for the ping, see composer/composer@f4738d97b (I guess that's why you pinged me :) |