Skip to content

Commit

Permalink
[Parallel] Display stack trace on --debug on parallel (#2561)
Browse files Browse the repository at this point in the history
* [Parallel] Display stack trace on --debug on parallel

* enhance

* enhance

* phpstan
  • Loading branch information
samsonasik committed Jun 25, 2022
1 parent 38b6b60 commit 24d2250
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions packages/Parallel/WorkerRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,6 +35,7 @@ public function __construct(
private readonly PhpFileProcessor $phpFileProcessor,
private readonly NodeScopeResolver $nodeScopeResolver,
private readonly DynamicSourceLocatorDecorator $dynamicSourceLocatorDecorator,
private readonly RectorConsoleOutputStyle $rectorConsoleOutputStyle
) {
}

Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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;
}
}

0 comments on commit 24d2250

Please sign in to comment.