8000 Always show a stack trace for \Error & LogicException throwables even… · composer/composer@af3e67e · GitHub
[go: up one dir, main page]

Skip to content

Commit af3e67e

Browse files
committed
Always show a stack trace for \Error & LogicException throwables even if output is not verbose
1 parent d1fa5d1 commit af3e67e

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

src/Composer/Console/Application.php

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616
use Composer\Util\Filesystem;
1717
use Composer\Util\Platform;
1818
use Composer\Util\Silencer;
19+
use LogicException;
1920
use Symfony\Component\Console\Application as BaseApplication;
2021
use Symfony\Component\Console\Exception\CommandNotFoundException;
2122
use Symfony\Component\Console\Helper\HelperSet;
2223
use Symfony\Component\Console\Helper\QuestionHelper;
2324
use Symfony\Component\Console\Input\InputDefinition;
2425
use Symfony\Component\Console\Input\InputInterface;
2526
use Symfony\Component\Console\Input\InputOption;
27+
use Symfony\Component\Console\Output\ConsoleOutputInterface;
2628
use Symfony\Component\Console\Output\OutputInterface;
2729
use Seld\JsonLint\ParsingException;
2830
use Composer\Command;
@@ -343,11 +345,33 @@ function_exists('php_uname') ? php_uname('s') . ' / ' . php_uname('r') : 'Unknow
343345
return $result;
344346
} catch (ScriptExecutionException $e) {
345347
return $e->getCode();
346-
} catch (\Exception $e) {
348+
} catch (\Throwable $e) {
347349
$ghe = new GithubActionError($this->io);
348350
$ghe->emit($e->getMessage());
349351

350-
$this->hintCommonErrors($e);
352+
$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+
}
351375

352376
throw $e;
353377
} finally {
@@ -374,10 +398,14 @@ private function getNewWorkingDir(InputInterface $input): ?string
374398
/**
375399
* @return void
376400
*/
377-
private function hintCommonErrors(\Exception $exception): void
401+
private function hintCommonErrors(\Throwable $exception, OutputInterface $output): void
378402
{
379403
$io = $this->getIO();
380404

405+
if ((get_class($exception) === LogicException::class || $exception instanceof \Error) && $output->getVerbosity() < OutputInterface::VERBOSITY_VERBOSE) {
406+
$output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE);
407+
}
408+
381409
Silencer::suppress();
382410
try {
383411
$composer = $this->getComposer(false, true);

src/Composer/Util/HttpDownloader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ public static function outputWarnings(IOInterface $io, string $url, $data): void
479479
*
480480
* @return ?string[]
481481
*/
482-
public static function getExceptionHints(\Exception $e): ?array
482+
public static function getExceptionHints(\Throwable $e): ?array
483483
{
484484
if (!$e instanceof TransportException) {
485485
return null;

0 commit comments

Comments
 (0)
0