Skip to content

Commit

Permalink
Pass verbosity to workers and show stack trace on error (#935)
Browse files Browse the repository at this point in the history
  • Loading branch information
benja-M-1 committed Jan 28, 2022
1 parent d33a581 commit a215b37
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/Command/WorkerCommand.php
Expand Up @@ -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;
Expand All @@ -222,12 +219,14 @@ 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',
);

$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;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/Process/ProcessHelper.php
Expand Up @@ -53,6 +53,7 @@ public static function getWorkerCommand(
'autoload-file',
'memory-limit',
'xdebug',
'verbose',
];
foreach ($options as $optionName) {
/** @var bool|string|null $optionValue */
Expand Down

0 comments on commit a215b37

Please sign in to comment.