Skip to content

Commit

Permalink
refletc json output formatter in fatal error on container creationg
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Jul 6, 2021
1 parent 95e6a5e commit ca44648
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions bin/rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

declare(strict_types=1);

use Nette\Utils\Json;
use Rector\ChangesReporting\Output\JsonOutputFormatter;
use Rector\Core\Bootstrap\RectorConfigsResolver;
use Rector\Core\Configuration\Option;
use Rector\Core\Console\ConsoleApplication;
use Rector\Core\Console\Style\SymfonyStyleFactory;
use Rector\Core\DependencyInjection\RectorContainerFactory;
Expand Down Expand Up @@ -41,17 +44,29 @@
$autoloadIncluder->autoloadProjectAutoloaderFile();
$autoloadIncluder->autoloadFromCommandLine();

$symfonyStyleFactory = new SymfonyStyleFactory(new PrivatesCaller());
$symfonyStyle = $symfonyStyleFactory->create();

$rectorConfigsResolver = new RectorConfigsResolver();

try {
$bootstrapConfigs = $rectorConfigsResolver->provide();
$rectorContainerFactory = new RectorContainerFactory();
$container = $rectorContainerFactory->createFromBootstrapConfigs($bootstrapConfigs);
} catch (Throwable $throwable) {
$symfonyStyle->error($throwable->getMessage());
// for json output
$argvInput = new \Symfony\Component\Console\Input\ArgvInput();
$outputFormat = $argvInput->getParameterOption('--' . Option::OUTPUT_FORMAT);

// report fatal error in json format
if ($outputFormat === JsonOutputFormatter::NAME) {
echo Json::encode([
'fatal_errors' => [$throwable->getMessage()],
]);
} else {
// report fatal errors in console format
$symfonyStyleFactory = new SymfonyStyleFactory(new PrivatesCaller());
$symfonyStyle = $symfonyStyleFactory->create();
$symfonyStyle->error($throwable->getMessage());
}

exit(ShellCode::ERROR);
}

Expand Down

0 comments on commit ca44648

Please sign in to comment.