Skip to content

Commit a99c71e

Browse files
committed
PHPStan Pro - report fatal errors more nicely
1 parent b88116b commit a99c71e

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/Command/FixerApplication.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
use PHPStan\Internal\DirectoryCreator;
2121
use PHPStan\Internal\DirectoryCreatorException;
2222
use PHPStan\PhpDoc\StubFilesProvider;
23+
use PHPStan\Process\ProcessCanceledException;
24+
use PHPStan\Process\ProcessCrashedException;
2325
use PHPStan\Process\ProcessHelper;
2426
use PHPStan\Process\ProcessPromise;
2527
use PHPStan\ShouldNotHappenException;
@@ -479,12 +481,24 @@ private function analyse(
479481
$this->processInProgress = null;
480482
$server->close();
481483
$output->writeln('<error>Worker process exited: ' . $e->getMessage() . '</error>');
484+
485+
if ($e instanceof ProcessCanceledException) {
486+
return;
487+
}
488+
489+
if ($e instanceof ProcessCrashedException) {
490+
$message = 'Analysis crashed';
491+
$trace = $e->getMessage();
492+
} else {
493+
$message = $e->getMessage();
494+
$trace = $e->getTraceAsString();
495+
}
482496
$phpstanFixerEncoder->write(['action' => 'analysisCrash', 'data' => [
483497
'internalErrors' => [new InternalError(
484-
$e->getMessage(),
498+
$message,
485499
'running PHPStan Pro worker',
486500
InternalError::prepareTrace($e),
487-
$e->getTraceAsString(),
501+
$trace,
488502
false,
489503
)],
490504
]]);

0 commit comments

Comments
 (0)