Skip to content

Commit

Permalink
Nicer error message in case of memory limit exhaustion in child process
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jan 3, 2024
1 parent 234772c commit 816be99
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/Parallel/ParallelAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
use function array_sum;
use function count;
use function defined;
use function ini_get;
use function is_string;
use function max;
use function memory_get_usage;
use function parse_url;
use function sprintf;
use function str_contains;
use const PHP_URL_PORT;

class ParallelAnalyser
Expand Down Expand Up @@ -204,7 +206,26 @@ public function analyse(
return;
}

$internalErrors[] = sprintf('Child process error (exit code %d): %s', $exitCode, $output);
$memoryLimitMessage = 'PHPStan process crashed because it reached configured PHP memory limit';
if (str_contains($output, $memoryLimitMessage)) {
foreach ($internalErrors as $internalError) {
if (!str_contains($internalError, $memoryLimitMessage)) {
continue;
}

return;
}
$internalErrors[] = sprintf(sprintf(
"<error>Child process error</error>: %s: %s\n%s\n",
$memoryLimitMessage,
ini_get('memory_limit'),
'Increase your memory limit in php.ini or run PHPStan with --memory-limit CLI option.',
));
$internalErrorsCount++;
return;
}

$internalErrors[] = sprintf('<error>Child process error</error> (exit code %d): %s', $exitCode, $output);
$internalErrorsCount++;
});
$this->processPool->attachProcess($processIdentifier, $process);
Expand Down

0 comments on commit 816be99

Please sign in to comment.