Skip to content

Commit

Permalink
[Parallel] Fix system errors expected an instance of SystemError but …
Browse files Browse the repository at this point in the history
…got string (#1610)
  • Loading branch information
zingimmick authored and samsonasik committed Jan 4, 2022
1 parent 2fa45d5 commit bb5609c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions packages/Parallel/Application/ParallelFileProcessor.php
Expand Up @@ -74,6 +74,7 @@ public function process(

// initial counters
$fileDiffs = [];
/** @var SystemError[] $systemErrors */
$systemErrors = [];

$tcpServer = new TcpServer('127.0.0.1:0', $streamSelectLoop);
Expand Down Expand Up @@ -166,7 +167,7 @@ function (array $json) use (
// decode arrays to objects
foreach ($json[Bridge::SYSTEM_ERRORS] as $jsonError) {
if (is_string($jsonError)) {
$systemErrors[] = 'System error: ' . $jsonError;
$systemErrors[] = new SystemError('System error: ' . $jsonError);
continue;
}

Expand Down Expand Up @@ -211,7 +212,7 @@ function ($exitCode, string $stdErr) use (&$systemErrors, $processIdentifier): v
return;
}

$systemErrors[] = 'Child process error: ' . $stdErr;
$systemErrors[] = new SystemError('Child process error: ' . $stdErr);
}
);

Expand All @@ -221,10 +222,10 @@ function ($exitCode, string $stdErr) use (&$systemErrors, $processIdentifier): v
$streamSelectLoop->run();

if ($reachedSystemErrorsCountLimit) {
$systemErrors[] = sprintf(
$systemErrors[] = new SystemError(sprintf(
'Reached system errors count limit of %d, exiting...',
self::SYSTEM_ERROR_COUNT_LIMIT
);
));
}

return [
Expand Down
6 changes: 3 additions & 3 deletions src/ValueObject/Error/SystemError.php
Expand Up @@ -11,7 +11,7 @@ final class SystemError implements SerializableInterface
{
public function __construct(
private readonly string $message,
private readonly string $relativeFilePath,
private readonly string|null $relativeFilePath = null,
private readonly int|null $line = null,
private readonly string|null $rectorClass = null
) {
Expand All @@ -22,7 +22,7 @@ public function getMessage(): string
return $this->message;
}

public function getFile(): string
public function getFile(): string|null
{
return $this->relativeFilePath;
}
Expand All @@ -38,7 +38,7 @@ public function getFileWithLine(): string
}

/**
* @return array{message: string, relative_file_path: string, line: int|null, rector_class: string|null}
* @return array{message: string, relative_file_path: string|null, line: int|null, rector_class: string|null}
*/
public function jsonSerialize(): array
{
Expand Down

0 comments on commit bb5609c

Please sign in to comment.