|
28 | 28 | use Symfony\Component\Console\Input\InputOption;
|
29 | 29 | use Symfony\Component\Console\Output\OutputInterface;
|
30 | 30 | use function array_diff;
|
| 31 | +use function array_key_exists; |
31 | 32 | use function count;
|
32 | 33 | use function filemtime;
|
33 | 34 | use function in_array;
|
@@ -232,11 +233,45 @@ function (array $errors, array $locallyIgnoredErrors, array $analysedFiles) use
|
232 | 233 | )->getAnalyserResult();
|
233 | 234 | $finalizerResult = $analyserResultFinalizer->finalize($analyserResult, $isOnlyFiles);
|
234 | 235 |
|
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(); |
236 | 271 |
|
237 | 272 | if ($hasInternalErrors) {
|
238 | 273 | $out->write(['action' => 'analysisCrash', 'data' => [
|
239 |
| - 'internalErrors' => count($finalizerResult->getAnalyserResult()->getInternalErrors()) > 0 ? $finalizerResult->getAnalyserResult()->getInternalErrors() : [ |
| 274 | + 'internalErrors' => count($internalErrors) > 0 ? $internalErrors : [ |
240 | 275 | new InternalError(
|
241 | 276 | 'Internal error occurred',
|
242 | 277 | 'running analyser in PHPStan Pro worker',
|
|
0 commit comments