Skip to content

Commit 3966299

Browse files
committed
Pass errors with non-ignorable exception as internal errors to PHPStan Pro
1 parent 3cd6416 commit 3966299

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

src/Command/FixerWorkerCommand.php

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use Symfony\Component\Console\Input\InputOption;
2929
use Symfony\Component\Console\Output\OutputInterface;
3030
use function array_diff;
31+
use function array_key_exists;
3132
use function count;
3233
use function filemtime;
3334
use function in_array;
@@ -232,11 +233,45 @@ function (array $errors, array $locallyIgnoredErrors, array $analysedFiles) use
232233
)->getAnalyserResult();
233234
$finalizerResult = $analyserResultFinalizer->finalize($analyserResult, $isOnlyFiles);
234235

235-
$hasInternalErrors = count($finalizerResult->getAnalyserResult()->getInternalErrors()) > 0 || $finalizerResult->getAnalyserResult()->hasReachedInternalErrorsCountLimit();
236+
$internalErrors = [];
237+
foreach ($finalizerResult->getAnalyserResult()->getInternalErrors() as $internalError) {
238+
$internalErrors[] = new InternalError(
239+
$internalError->getTraceAsString() !== null ? sprintf('Internal error: %s', $internalError->getMessage()) : $internalError->getMessage(),
240+
$internalError->getContextDescription(),
241+
$internalError->getTrace(),
242+
$internalError->getTraceAsString(),
243+
$internalError->shouldReportBug(),
244+
);
245+
}
246+
247+
foreach ($finalizerResult->getAnalyserResult()->getUnorderedErrors() as $fileSpecificError) {
248+
if (!$fileSpecificError->hasNonIgnorableException()) {
249+
continue;
250+
}
251+
252+
$message = $fileSpecificError->getMessage();
253+
$metadata = $fileSpecificError->getMetadata();
254+
if (
255+
$fileSpecificError->getIdentifier() === 'phpstan.internal'
256+
&& array_key_exists(InternalError::STACK_TRACE_AS_STRING_METADATA_KEY, $metadata)
257+
) {
258+
$message = sprintf('Internal error: %s', $message);
259+
}
260+
261+
$internalErrors[] = new InternalError(
262+
$message,
263+
sprintf('analysing file %s', $fileSpecificError->getTraitFilePath() ?? $fileSpecificError->getFilePath()),
264+
$metadata[InternalError::STACK_TRACE_METADATA_KEY] ?? [],
265+
$metadata[InternalError::STACK_TRACE_AS_STRING_METADATA_KEY] ?? null,
266+
true,
267+
);
268+
}
269+
270+
$hasInternalErrors = count($internalErrors) > 0 || $finalizerResult->getAnalyserResult()->hasReachedInternalErrorsCountLimit();
236271

237272
if ($hasInternalErrors) {
238273
$out->write(['action' => 'analysisCrash', 'data' => [
239-
'internalErrors' => count($finalizerResult->getAnalyserResult()->getInternalErrors()) > 0 ? $finalizerResult->getAnalyserResult()->getInternalErrors() : [
274+
'internalErrors' => count($internalErrors) > 0 ? $internalErrors : [
240275
new InternalError(
241276
'Internal error occurred',
242277
'running analyser in PHPStan Pro worker',

0 commit comments

Comments
 (0)