mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-18 22:08:00 +01:00
make error on process non-blocking
This commit is contained in:
parent
316830f50c
commit
db0fef557d
1
ecs.yml
1
ecs.yml
@ -20,6 +20,7 @@ services:
|
||||
- 'Rector\RectorDefinition\*'
|
||||
- 'PHPStan\Analyser\Scope'
|
||||
- 'PhpParser\NodeVisitor\NameResolver'
|
||||
- 'Rector\Application\Error'
|
||||
|
||||
Symplify\CodingStandard\Fixer\Naming\PropertyNameMatchingTypeFixer:
|
||||
extra_skipped_classes:
|
||||
|
45
src/Application/Error.php
Normal file
45
src/Application/Error.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\Application;
|
||||
|
||||
use Symfony\Component\Finder\SplFileInfo;
|
||||
|
||||
final class Error
|
||||
{
|
||||
/**
|
||||
* @var SplFileInfo
|
||||
*/
|
||||
private $fileInfo;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $message;
|
||||
|
||||
/**
|
||||
* @var int|null
|
||||
*/
|
||||
private $line;
|
||||
|
||||
public function __construct(SplFileInfo $fileInfo, string $message, ?int $line)
|
||||
{
|
||||
$this->fileInfo = $fileInfo;
|
||||
$this->message = $message;
|
||||
$this->line = $line;
|
||||
}
|
||||
|
||||
public function getFileInfo(): SplFileInfo
|
||||
{
|
||||
return $this->fileInfo;
|
||||
}
|
||||
|
||||
public function getMessage(): string
|
||||
{
|
||||
return $this->message;
|
||||
}
|
||||
|
||||
public function getLine(): ?int
|
||||
{
|
||||
return $this->line;
|
||||
}
|
||||
}
|
@ -3,13 +3,14 @@
|
||||
namespace Rector\Console\Command;
|
||||
|
||||
use Nette\Utils\FileSystem;
|
||||
use PHPStan\AnalysedCodeException;
|
||||
use Rector\Application\Error;
|
||||
use Rector\Application\FileProcessor;
|
||||
use Rector\Autoloading\AdditionalAutoloader;
|
||||
use Rector\Configuration\Option;
|
||||
use Rector\Console\ConsoleStyle;
|
||||
use Rector\Console\Output\ProcessCommandReporter;
|
||||
use Rector\ConsoleDiffer\DifferAndFormatter;
|
||||
use Rector\Exception\Command\FileProcessingException;
|
||||
use Rector\FileSystem\FilesFinder;
|
||||
use Rector\Guard\RectorGuard;
|
||||
use Rector\Reporting\FileDiff;
|
||||
@ -82,6 +83,11 @@ final class ProcessCommand extends Command
|
||||
*/
|
||||
private $rectorGuard;
|
||||
|
||||
/**
|
||||
* @var Error[]
|
||||
*/
|
||||
private $errors = [];
|
||||
|
||||
public function __construct(
|
||||
FileProcessor $fileProcessor,
|
||||
ConsoleStyle $consoleStyle,
|
||||
@ -157,6 +163,11 @@ final class ProcessCommand extends Command
|
||||
$this->processCommandReporter->reportFileDiffs($this->fileDiffs);
|
||||
$this->processCommandReporter->reportChangedFiles($this->changedFiles);
|
||||
|
||||
if ($this->errors) {
|
||||
$this->processCommandReporter->reportErrors($this->errors);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ($input->getOption(Option::OPTION_WITH_STYLE)) {
|
||||
$command = sprintf('vendor/bin/ecs check %s --config ecs-after-rector.yml --fix', implode(' ', $source));
|
||||
|
||||
@ -189,13 +200,15 @@ final class ProcessCommand extends Command
|
||||
} elseif ($fileInfo->getExtension() === 'yml') {
|
||||
$this->processYamlFile($fileInfo);
|
||||
}
|
||||
} catch (Throwable $throwable) {
|
||||
$this->consoleStyle->newLine();
|
||||
throw new FileProcessingException(
|
||||
sprintf('Processing of "%s" file failed.', $fileInfo->getPathname()),
|
||||
$throwable->getCode(),
|
||||
$throwable
|
||||
} catch (AnalysedCodeException $analysedCodeException) {
|
||||
$message = sprintf(
|
||||
'Analyze error: %s Try to include your files in "parameters > autoload_files" or "parameters > autoload_directories".%sSee https://github.com/rectorphp/rector#extra-autoloading',
|
||||
$analysedCodeException->getMessage(),
|
||||
PHP_EOL
|
||||
);
|
||||
$this->errors[] = new Error($fileInfo, $message, null);
|
||||
} catch (Throwable $throwable) {
|
||||
$this->errors[] = new Error($fileInfo, $throwable->getMessage(), $throwable->getCode());
|
||||
}
|
||||
|
||||
$this->consoleStyle->progressAdvance();
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace Rector\Console\Output;
|
||||
|
||||
use Rector\Application\Error;
|
||||
use Rector\Console\ConsoleStyle;
|
||||
use Rector\Contract\Rector\RectorInterface;
|
||||
use Rector\NodeTraverser\RectorNodeTraverser;
|
||||
@ -92,4 +93,25 @@ final class ProcessCommandReporter
|
||||
$this->consoleStyle->newLine();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Error[] $errors
|
||||
*/
|
||||
public function reportErrors(array $errors): void
|
||||
{
|
||||
foreach ($errors as $error) {
|
||||
$message = sprintf(
|
||||
'Could not process "%s" file, due to: %s"%s".',
|
||||
$error->getFileInfo()->getPathname(),
|
||||
PHP_EOL,
|
||||
$error->getMessage()
|
||||
);
|
||||
|
||||
if ($error->getLine()) {
|
||||
$message .= ' On line: ' . $error->getLine();
|
||||
}
|
||||
|
||||
$this->consoleStyle->error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ services:
|
||||
|
||||
Rector\:
|
||||
resource: '../'
|
||||
exclude: '../{Node/Attribute.php,Rector/**/*Rector.php,Reporting/FileDiff.php,Testing,RectorDefinition,*/*/*Info.php,Configuration/Rector/*Recipe.php,Exception/*,DependencyInjection/CompilerPass/*}'
|
||||
exclude: '../{Node/Attribute.php,Rector/**/*Rector.php,Reporting/FileDiff.php,Testing,RectorDefinition,*/*/*Info.php,Configuration/Rector/*Recipe.php,Exception/*,DependencyInjection/CompilerPass/*,Application/Error.php}'
|
||||
|
||||
# extra services
|
||||
Rector\Symfony\Rector\Form\Helper\FormTypeStringToTypeProvider: ~
|
||||
|
Loading…
x
Reference in New Issue
Block a user