Skip to content

Commit 816be99

Browse files
committed
Nicer error message in case of memory limit exhaustion in child process
1 parent 234772c commit 816be99

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/Parallel/ParallelAnalyser.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222
use function array_sum;
2323
use function count;
2424
use function defined;
25+
use function ini_get;
2526
use function is_string;
2627
use function max;
2728
use function memory_get_usage;
2829
use function parse_url;
2930
use function sprintf;
31+
use function str_contains;
3032
use const PHP_URL_PORT;
3133

3234
class ParallelAnalyser
@@ -204,7 +206,26 @@ public function analyse(
204206
return;
205207
}
206208

207-
$internalErrors[] = sprintf('Child process error (exit code %d): %s', $exitCode, $output);
209+
$memoryLimitMessage = 'PHPStan process crashed because it reached configured PHP memory limit';
210+
if (str_contains($output, $memoryLimitMessage)) {
211+
foreach ($internalErrors as $internalError) {
212+
if (!str_contains($internalError, $memoryLimitMessage)) {
213+
continue;
214+
}
215+
216+
return;
217+
}
218+
$internalErrors[] = sprintf(sprintf(
219+
"<error>Child process error</error>: %s: %s\n%s\n",
220+
$memoryLimitMessage,
221+
ini_get('memory_limit'),
222+
'Increase your memory limit in php.ini or run PHPStan with --memory-limit CLI option.',
223+
));
224+
$internalErrorsCount++;
225+
return;
226+
}
227+
228+
$internalErrors[] = sprintf('<error>Child process error</error> (exit code %d): %s', $exitCode, $output);
208229
$internalErrorsCount++;
209230
});
210231
$this->processPool->attachProcess($processIdentifier, $process);

0 commit comments

Comments
 (0)