From 13a86134ccf22e7f526971b1c521078521d12b01 Mon Sep 17 00:00:00 2001 From: Benjamin Grandfond Date: Sat, 22 Jan 2022 01:08:31 +0100 Subject: [PATCH 1/4] Pass verbosity to workers and show stack trace on error --- src/Command/WorkerCommand.php | 17 +++++++---------- src/Process/ProcessHelper.php | 1 + 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/Command/WorkerCommand.php b/src/Command/WorkerCommand.php index 711359314d..9104d4617a 100644 --- a/src/Command/WorkerCommand.php +++ b/src/Command/WorkerCommand.php @@ -188,14 +188,11 @@ private function runWorker( $out->end(); }; $out->on('error', $handleError); - /** @var FileAnalyser $fileAnalyser */ $fileAnalyser = $container->getByType(FileAnalyser::class); - /** @var Registry $registry */ $registry = $container->getByType(Registry::class); - - $in->on('data', function (array $json) use ($fileAnalyser, $registry, $out, $analysedFiles, $tmpFile, $insteadOfFile): void { + $in->on('data', function (array $json) use ($fileAnalyser, $registry, $out, $analysedFiles, $tmpFile, $insteadOfFile, $output): void { $action = $json['action']; if ($action !== 'analyse') { return; @@ -222,12 +219,12 @@ private function runWorker( $this->errorCount++; $internalErrorsCount++; $internalErrorMessage = sprintf('Internal error: %s in file %s', $t->getMessage(), $file); - $internalErrorMessage .= sprintf( - '%sRun PHPStan with --debug option and post the stack trace to:%s%s', - "\n", - "\n", - 'https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md', - ); + $internalErrorMessage .= sprintf('%sRun PHPStan with --debug option and post the stack trace to:%s%s', "\n", "\n", 'https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md'); + + if (OutputInterface::VERBOSITY_VERBOSE >= $output->getVerbosity()) { + $internalErrorMessage .= sprintf('%sStack trace: %s%s', "\n\n", "\n", $t->getTraceAsString()); + } + $errors[] = $internalErrorMessage; } } diff --git a/src/Process/ProcessHelper.php b/src/Process/ProcessHelper.php index f01917130c..6206a1fcb0 100644 --- a/src/Process/ProcessHelper.php +++ b/src/Process/ProcessHelper.php @@ -53,6 +53,7 @@ public static function getWorkerCommand( 'autoload-file', 'memory-limit', 'xdebug', + 'verbose' ]; foreach ($options as $optionName) { /** @var bool|string|null $optionValue */ From a9340006a8e40026d9ad712d05d2b798866fcace Mon Sep 17 00:00:00 2001 From: Benjamin Grandfond Date: Sat, 22 Jan 2022 11:12:23 +0100 Subject: [PATCH 2/4] Change instruction to use -v instead of --debug option --- src/Command/WorkerCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Command/WorkerCommand.php b/src/Command/WorkerCommand.php index 9104d4617a..7694cffbd1 100644 --- a/src/Command/WorkerCommand.php +++ b/src/Command/WorkerCommand.php @@ -219,7 +219,7 @@ private function runWorker( $this->errorCount++; $internalErrorsCount++; $internalErrorMessage = sprintf('Internal error: %s in file %s', $t->getMessage(), $file); - $internalErrorMessage .= sprintf('%sRun PHPStan with --debug option and post the stack trace to:%s%s', "\n", "\n", 'https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md'); + $internalErrorMessage .= sprintf('%sRun PHPStan with -v option and post the stack trace to:%s%s', "\n", "\n", 'https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md'); if (OutputInterface::VERBOSITY_VERBOSE >= $output->getVerbosity()) { $internalErrorMessage .= sprintf('%sStack trace: %s%s', "\n\n", "\n", $t->getTraceAsString()); From 361ad00669816d2d0747583a0c1b4a7c80a97808 Mon Sep 17 00:00:00 2001 From: Benjamin Grandfond Date: Sat, 22 Jan 2022 13:30:27 +0100 Subject: [PATCH 3/4] Add trailing comma in array --- src/Process/ProcessHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Process/ProcessHelper.php b/src/Process/ProcessHelper.php index 6206a1fcb0..2597e771a8 100644 --- a/src/Process/ProcessHelper.php +++ b/src/Process/ProcessHelper.php @@ -53,7 +53,7 @@ public static function getWorkerCommand( 'autoload-file', 'memory-limit', 'xdebug', - 'verbose' + 'verbose', ]; foreach ($options as $optionName) { /** @var bool|string|null $optionValue */ From abd7db80e62cef1cde35d307db2e13e0e540faab Mon Sep 17 00:00:00 2001 From: Benjamin Grandfond Date: Fri, 28 Jan 2022 09:24:00 +0100 Subject: [PATCH 4/4] Change message if -v option whether has been set or not --- src/Command/WorkerCommand.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Command/WorkerCommand.php b/src/Command/WorkerCommand.php index 7694cffbd1..122d3b4aa3 100644 --- a/src/Command/WorkerCommand.php +++ b/src/Command/WorkerCommand.php @@ -219,10 +219,12 @@ private function runWorker( $this->errorCount++; $internalErrorsCount++; $internalErrorMessage = sprintf('Internal error: %s in file %s', $t->getMessage(), $file); - $internalErrorMessage .= sprintf('%sRun PHPStan with -v option and post the stack trace to:%s%s', "\n", "\n", 'https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md'); - if (OutputInterface::VERBOSITY_VERBOSE >= $output->getVerbosity()) { - $internalErrorMessage .= sprintf('%sStack trace: %s%s', "\n\n", "\n", $t->getTraceAsString()); + $bugReportUrl = 'https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md'; + if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { + $internalErrorMessage .= sprintf('%sPost the following stack trace to %s: %s%s', "\n\n", $bugReportUrl, "\n", $t->getTraceAsString()); + } else { + $internalErrorMessage .= sprintf('%sRun PHPStan with -v option and post the stack trace to:%s%s', "\n", "\n", $bugReportUrl); } $errors[] = $internalErrorMessage;