16
16
use Composer \Util \Filesystem ;
17
17
use Composer \Util \Platform ;
18
18
use Composer \Util \Silencer ;
19
+ use LogicException ;
19
20
use Symfony \Component \Console \Application as BaseApplication ;
20
21
use Symfony \Component \Console \Exception \CommandNotFoundException ;
21
22
use Symfony \Component \Console \Helper \HelperSet ;
22
23
use Symfony \Component \Console \Helper \QuestionHelper ;
23
24
use Symfony \Component \Console \Input \InputDefinition ;
24
25
use Symfony \Component \Console \Input \InputInterface ;
25
26
use Symfony \Component \Console \Input \InputOption ;
27
+ use Symfony \Component \Console \Output \ConsoleOutputInterface ;
26
28
use Symfony \Component \Console \Output \OutputInterface ;
27
29
use Seld \JsonLint \ParsingException ;
28
30
use Composer \Command ;
@@ -343,11 +345,33 @@ function_exists('php_uname') ? php_uname('s') . ' / ' . php_uname('r') : 'Unknow
343
345
return $ result ;
344
346
} catch (ScriptExecutionException $ e ) {
345
347
return $ e ->getCode ();
346
- } catch (\Exception $ e ) {
348
+ } catch (\Throwable $ e ) {
347
349
$ ghe = new GithubActionError ($ this ->io );
348
350
$ ghe ->emit ($ e ->getMessage ());
349
351
350
- $ this ->hintCommonErrors ($ e );
352
+
10000
span> $ this ->hintCommonErrors ($ e , $ output );
353
+
354
+ // symfony/console does not handle \Error subtypes so we have to renderThrowable ourselves
355
+ // instead of rethrowing those for consumption by the parent class
356
+ if (!$ e instanceof \Exception) {
357
+ if ($ output instanceof ConsoleOutputInterface) {
358
+ $ this ->renderThrowable ($ e , $ output ->getErrorOutput ());
359
+ } else {
360
+ $ this ->renderThrowable ($ e , $ output );
361
+ }
362
+
363
+ $ exitCode = $ e ->getCode ();
364
+ if (is_numeric ($ exitCode )) {
365
+ $ exitCode = (int ) $ exitCode ;
366
+ if (0 === $ exitCode ) {
367
+ $ exitCode = 1 ;
368
+ }
369
+ } else {
370
+ $ exitCode = 1 ;
371
+ }
372
+
373
+ return $ exitCode ;
374
+ }
351
375
352
376
throw $ e ;
353
377
} finally {
@@ -374,10 +398,14 @@ private function getNewWorkingDir(InputInterface $input): ?string
374
398
/**
375
399
* @return void
376
400
*/
377
- private function hintCommonErrors (\Exception $ exception ): void
401
+ private function hintCommonErrors (\Throwable $ exception, OutputInterface $ output ): void
378
402
{
379
403
$ io = $ this ->getIO ();
380
404
405
+ if ((get_class ($ exception ) === LogicException::class || $ exception instanceof \Error) && $ output ->getVerbosity () < OutputInterface::VERBOSITY_VERBOSE ) {
406
+ $ output ->setVerbosity (OutputInterface::VERBOSITY_VERBOSE );
407
+ }
408
+
381
409
Silencer::suppress ();
382
410
try {
383
411
$ composer = $ this ->getComposer (false , true );
0 commit comments