From 854f2b272a08764286b33ff0d70964e9ee527542 Mon Sep 17 00:00:00 2001 From: Markus Staab <47448731+clxmstaab@users.noreply.github.com> Date: Wed, 6 Nov 2019 09:51:10 +0100 Subject: [PATCH 1/6] Let exceptions fly while bootstrapping that way we get a proper exception stacktrace on the CLI --- src/Command/AnalyseCommand.php | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/Command/AnalyseCommand.php b/src/Command/AnalyseCommand.php index e723a32189..c61d1f8e0c 100644 --- a/src/Command/AnalyseCommand.php +++ b/src/Command/AnalyseCommand.php @@ -77,21 +77,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int throw new \PHPStan\ShouldNotHappenException(); } - try { - $inceptionResult = CommandHelper::begin( - $input, - $output, - $paths, - $pathsFile, - $memoryLimit, - $autoloadFile, - $configuration, - $level, - $allowXdebug - ); - } catch (\PHPStan\Command\InceptionNotSuccessfulException $e) { - return 1; - } + $inceptionResult = CommandHelper::begin( + $input, + $output, + $paths, + $pathsFile, + $memoryLimit, + $autoloadFile, + $configuration, + $level, + $allowXdebug + ); $errorOutput = $inceptionResult->getErrorOutput(); $errorFormat = $input->getOption('error-format'); From f68f38ce1de86b01548e353480fbce1b7defdb33 Mon Sep 17 00:00:00 2001 From: Markus Staab <47448731+clxmstaab@users.noreply.github.com> Date: Wed, 6 Nov 2019 09:59:55 +0100 Subject: [PATCH 2/6] Adding the exception-cause to bootstrapping errors --- src/Command/CommandHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Command/CommandHelper.php b/src/Command/CommandHelper.php index 46861f1246..66fab81a1a 100644 --- a/src/Command/CommandHelper.php +++ b/src/Command/CommandHelper.php @@ -303,7 +303,7 @@ public static function begin( })($bootstrapFile); } catch (\Throwable $e) { $errorOutput->writeln($e->getMessage()); - throw new \PHPStan\Command\InceptionNotSuccessfulException(); + throw new \PHPStan\Command\InceptionNotSuccessfulException($e->getMessage(), 0, $e); } } From 252c458e36eb86ab3a288f4c87d01526bde1b3e9 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 6 Nov 2019 12:04:49 +0100 Subject: [PATCH 3/6] Revert "Let exceptions fly while bootstrapping" This reverts commit 854f2b272a08764286b33ff0d70964e9ee527542. --- src/Command/AnalyseCommand.php | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/Command/AnalyseCommand.php b/src/Command/AnalyseCommand.php index c61d1f8e0c..e723a32189 100644 --- a/src/Command/AnalyseCommand.php +++ b/src/Command/AnalyseCommand.php @@ -77,17 +77,21 @@ protected function execute(InputInterface $input, OutputInterface $output): int throw new \PHPStan\ShouldNotHappenException(); } - $inceptionResult = CommandHelper::begin( - $input, - $output, - $paths, - $pathsFile, - $memoryLimit, - $autoloadFile, - $configuration, - $level, - $allowXdebug - ); + try { + $inceptionResult = CommandHelper::begin( + $input, + $output, + $paths, + $pathsFile, + $memoryLimit, + $autoloadFile, + $configuration, + $level, + $allowXdebug + ); + } catch (\PHPStan\Command\InceptionNotSuccessfulException $e) { + return 1; + } $errorOutput = $inceptionResult->getErrorOutput(); $errorFormat = $input->getOption('error-format'); From eb02a329195e4fd111189401a8ee2a5f12692ab3 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 6 Nov 2019 12:04:52 +0100 Subject: [PATCH 4/6] Revert "Adding the exception-cause to bootstrapping errors" This reverts commit f68f38ce1de86b01548e353480fbce1b7defdb33. --- src/Command/CommandHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Command/CommandHelper.php b/src/Command/CommandHelper.php index 66fab81a1a..46861f1246 100644 --- a/src/Command/CommandHelper.php +++ b/src/Command/CommandHelper.php @@ -303,7 +303,7 @@ public static function begin( })($bootstrapFile); } catch (\Throwable $e) { $errorOutput->writeln($e->getMessage()); - throw new \PHPStan\Command\InceptionNotSuccessfulException($e->getMessage(), 0, $e); + throw new \PHPStan\Command\InceptionNotSuccessfulException(); } } From baa885c542f6595c2f80966704298669be08add1 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 6 Nov 2019 13:10:15 +0100 Subject: [PATCH 5/6] use Symfony\Component\Console\Application::renderException() --- src/Command/AnalyseCommand.php | 3 ++- src/Command/CommandHelper.php | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Command/AnalyseCommand.php b/src/Command/AnalyseCommand.php index e723a32189..d2051503d5 100644 --- a/src/Command/AnalyseCommand.php +++ b/src/Command/AnalyseCommand.php @@ -87,7 +87,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int $autoloadFile, $configuration, $level, - $allowXdebug + $allowXdebug, + $this->getApplication() ); } catch (\PHPStan\Command\InceptionNotSuccessfulException $e) { return 1; diff --git a/src/Command/CommandHelper.php b/src/Command/CommandHelper.php index 46861f1246..8662c5d414 100644 --- a/src/Command/CommandHelper.php +++ b/src/Command/CommandHelper.php @@ -14,6 +14,7 @@ use PHPStan\DependencyInjection\NeonAdapter; use PHPStan\File\FileFinder; use PHPStan\File\FileHelper; +use Symfony\Component\Console\Application; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\ConsoleOutputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -36,7 +37,8 @@ public static function begin( ?string $autoloadFile, ?string $projectConfigFile, ?string $level, - bool $allowXdebug + bool $allowXdebug, + Application $application ): InceptionResult { if (!$allowXdebug) { @@ -129,7 +131,7 @@ public static function begin( try { $projectConfig = $loader->load($projectConfigFile, null); } catch (\Nette\InvalidStateException | \Nette\FileNotFoundException $e) { - $errorOutput->writeln($e->getMessage()); + $application->renderException($e); throw new \PHPStan\Command\InceptionNotSuccessfulException(); } $defaultParameters = [ @@ -302,7 +304,8 @@ public static function begin( require_once $file; })($bootstrapFile); } catch (\Throwable $e) { - $errorOutput->writeln($e->getMessage()); + $application->renderException($e); + throw new \PHPStan\Command\InceptionNotSuccessfulException(); } } From 84e81546e54fe55558ecb268f582a21cca40db34 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 6 Nov 2019 13:11:56 +0100 Subject: [PATCH 6/6] fix missing arg --- src/Command/DumpDependenciesCommand.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Command/DumpDependenciesCommand.php b/src/Command/DumpDependenciesCommand.php index ef9ce11596..d3815b144f 100644 --- a/src/Command/DumpDependenciesCommand.php +++ b/src/Command/DumpDependenciesCommand.php @@ -61,7 +61,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int $autoloadFile, $configurationFile, '0', // irrelevant but prevents an error when a config file is passed - $allowXdebug + $allowXdebug, + $this->getApplication() ); } catch (\PHPStan\Command\InceptionNotSuccessfulException $e) { return 1;