diff --git a/packages/Parallel/WorkerRunner.php b/packages/Parallel/WorkerRunner.php index 7ddc7778d7a..2b6f5f3ca98 100644 --- a/packages/Parallel/WorkerRunner.php +++ b/packages/Parallel/WorkerRunner.php @@ -8,6 +8,7 @@ use Clue\React\NDJson\Encoder; use PHPStan\Analyser\NodeScopeResolver; use Rector\Core\Application\FileProcessor\PhpFileProcessor; +use Rector\Core\Console\Style\RectorConsoleOutputStyle; use Rector\Core\Provider\CurrentFileProvider; use Rector\Core\StaticReflection\DynamicSourceLocatorDecorator; use Rector\Core\ValueObject\Application\File; @@ -34,6 +35,7 @@ public function __construct( private readonly PhpFileProcessor $phpFileProcessor, private readonly NodeScopeResolver $nodeScopeResolver, private readonly DynamicSourceLocatorDecorator $dynamicSourceLocatorDecorator, + private readonly RectorConsoleOutputStyle $rectorConsoleOutputStyle ) { } @@ -95,10 +97,7 @@ public function run(Encoder $encoder, Decoder $decoder, Configuration $configura ); } catch (Throwable $throwable) { ++$systemErrorsCount; - - $errorMessage = sprintf('System error: "%s"', $throwable->getMessage()) . PHP_EOL; - $errorMessage .= 'Run Rector with "--debug" option and post the report here: https://github.com/rectorphp/rector/issues/new'; - $systemErrors[] = new SystemError($errorMessage, $filePath, $throwable->getLine()); + $systemErrors = $this->collectSystemErrors($systemErrors, $throwable, $filePath); } } @@ -118,4 +117,27 @@ public function run(Encoder $encoder, Decoder $decoder, Configuration $configura $decoder->on(ReactEvent::ERROR, $handleErrorCallback); } + + /** + * @param SystemError[] $systemErrors + * @return SystemError[] + */ + private function collectSystemErrors(array $systemErrors, Throwable $throwable, string $filePath): array + { + $errorMessage = sprintf('System error: "%s"', $throwable->getMessage()) . PHP_EOL; + + if ($this->rectorConsoleOutputStyle->isDebug()) { + $systemErrors[] = new SystemError( + $errorMessage . PHP_EOL . 'Stack trace:' . PHP_EOL . $throwable->getTraceAsString(), + $filePath, + $throwable->getLine() + ); + return $systemErrors; + } + + $errorMessage .= 'Run Rector with "--debug" option and post the report here: https://github.com/rectorphp/rector/issues/new'; + $systemErrors[] = new SystemError($errorMessage, $filePath, $throwable->getLine()); + + return $systemErrors; + } }