Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Parallel] Fix system errors expected an instance of SystemError but got string #1610

Merged
merged 4 commits into from Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/Parallel/Application/ParallelFileProcessor.php
Expand Up @@ -166,7 +166,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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you type this array, so phpstan would error when strings are pushed onto the array?

Copy link
Contributor Author

@zingimmick zingimmick Jan 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a type to this array, but phpstan does not error when a string is pushed into the array. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not supported yet. phpstan/phpstan#3269, phpstan/phpstan#3703

continue;
}

Expand Down Expand Up @@ -211,7 +211,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 +221,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