@@ -330,45 +330,62 @@ protected function execute(InputInterface $input, OutputInterface $output): int
330
330
throw $ t ;
331
331
}
332
332
333
- $ internalErrors = [];
333
+ /**
334
+ * Variable $internalErrorsTuples contains both "internal errors"
335
+ * and "errors with non-ignorable exception" as InternalError objects.
336
+ */
337
+ $ internalErrorsTuples = [];
334
338
$ internalFileSpecificErrors = [];
335
339
foreach ($ analysisResult ->getInternalErrorObjects () as $ internalError ) {
336
- $ internalErrors [$ internalError ->getMessage ()] = new InternalError (
340
+ $ internalErrorsTuples [$ internalError ->getMessage ()] = [ new InternalError (
337
341
$ internalError ->getTraceAsString () !== null ? sprintf ('Internal error: %s ' , $ internalError ->getMessage ()) : $ internalError ->getMessage (),
338
342
$ internalError ->getContextDescription (),
339
343
$ internalError ->getTrace (),
340
344
$ internalError ->getTraceAsString (),
341
345
$ internalError ->shouldReportBug (),
342
- );
346
+ ), false ] ;
343
347
}
344
348
foreach ($ analysisResult ->getFileSpecificErrors () as $ fileSpecificError ) {
345
349
if (!$ fileSpecificError ->hasNonIgnorableException ()) {
346
350
continue ;
347
351
}
348
352
349
- $ internalFileSpecificErrors [] = $ fileSpecificError ;
350
-
351
353
$ message = $ fileSpecificError ->getMessage ();
352
354
$ metadata = $ fileSpecificError ->getMetadata ();
355
+ $ hasStackTrace = false ;
353
356
if (
354
357
$ fileSpecificError ->getIdentifier () === 'phpstan.internal '
355
358
&& array_key_exists (InternalError::STACK_TRACE_AS_STRING_METADATA_KEY , $ metadata )
356
359
) {
357
360
$ message = sprintf ('Internal error: %s ' , $ message );
361
+ $ hasStackTrace = true ;
358
362
}
359
363
360
- $ internalErrors [$ fileSpecificError ->getMessage ()] = new InternalError (
364
+ if (!$ hasStackTrace ) {
365
+ $ internalFileSpecificErrors [] = $ fileSpecificError ;
366
+ }
367
+
368
+ $ internalErrorsTuples [$ fileSpecificError ->getMessage ()] = [new InternalError (
361
369
$ message ,
362
370
sprintf ('analysing file %s ' , $ fileSpecificError ->getTraitFilePath () ?? $ fileSpecificError ->getFilePath ()),
363
371
$ metadata [InternalError::STACK_TRACE_METADATA_KEY ] ?? [],
364
372
$ metadata [InternalError::STACK_TRACE_AS_STRING_METADATA_KEY ] ?? null ,
365
373
true ,
366
- );
374
+ ), ! $ hasStackTrace ] ;
367
375
}
368
376
369
- $ internalErrors = array_values ($ internalErrors );
377
+ $ internalErrorsTuples = array_values ($ internalErrorsTuples );
370
378
$ bugReportUrl = 'https://github.com/phpstan/phpstan/issues/new?template=Bug_report.yaml ' ;
371
- foreach ($ internalErrors as $ i => $ internalError ) {
379
+
380
+ /**
381
+ * Variable $internalErrors only contains non-file-specific "internal errors".
382
+ */
383
+ $ internalErrors = [];
384
+ foreach ($ internalErrorsTuples as [$ internalError , $ isInFileSpecificErrors ]) {
385
+ if ($ isInFileSpecificErrors ) {
386
+ continue ;
387
+ }
388
+
372
389
$ message = sprintf ('%s while %s ' , $ internalError ->getMessage (), $ internalError ->getContextDescription ());
373
390
if ($ internalError ->getTraceAsString () !== null ) {
374
391
if (OutputInterface::VERBOSITY_VERBOSE <= $ output ->getVerbosity ()) {
@@ -393,7 +410,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
393
410
}
394
411
}
395
412
396
- $ internalErrors [$ i ] = new InternalError (
413
+ $ internalErrors [] = new InternalError (
397
414
$ message ,
398
415
$ internalError ->getContextDescription (),
399
416
$ internalError ->getTrace (),
@@ -402,11 +419,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
402
419
);
403
420
}
404
421
405
- $ internalErrors = array_values ($ internalErrors );
406
-
407
422
if ($ generateBaselineFile !== null ) {
408
- if (count ($ internalErrors ) > 0 ) {
409
- foreach ($ internalErrors as $ internalError ) {
423
+ if (count ($ internalErrorsTuples ) > 0 ) {
424
+ foreach ($ internalErrorsTuples as [ $ internalError] ) {
410
425
$ inceptionResult ->getStdOutput ()->writeLineFormatted ($ internalError ->getMessage ());
411
426
$ inceptionResult ->getStdOutput ()->writeLineFormatted ('' );
412
427
}
@@ -425,7 +440,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
425
440
/** @var ErrorFormatter $errorFormatter */
426
441
$ errorFormatter = $ container ->getService ($ errorFormatterServiceName );
427
442
428
- if (count ($ internalErrors ) > 0 ) {
443
+ if (count ($ internalErrorsTuples ) > 0 ) {
429
444
$ analysisResult = new AnalysisResult (
430
445
$ internalFileSpecificErrors ,
431
446
array_map (static fn (InternalError $ internalError ) => $ internalError ->getMessage (), $ internalErrors ),
0 commit comments