[Parallel] Display stack trace on --debug on parallel (#2561)

* [Parallel] Display stack trace on --debug on parallel

* enhance

* enhance

* phpstan
This commit is contained in:
Abdul Malik Ikhsan 2022-06-25 13:48:10 +07:00 committed by GitHub
parent 38b6b60b24
commit 24d2250c59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,6 +8,7 @@ use Clue\React\NDJson\Decoder;
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 @@ final class WorkerRunner
private readonly PhpFileProcessor $phpFileProcessor,
private readonly NodeScopeResolver $nodeScopeResolver,
private readonly DynamicSourceLocatorDecorator $dynamicSourceLocatorDecorator,
private readonly RectorConsoleOutputStyle $rectorConsoleOutputStyle
) {
}
@ -95,10 +97,7 @@ final class WorkerRunner
);
} 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 @@ final class WorkerRunner
$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;
}
}