[Console] add support for catching \Throwable errors
#50420
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 |
|
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 :) |