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

add back invalid cache reporting #9925

Closed
Closed
Changes from all 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
22 changes: 20 additions & 2 deletions src/Psalm/Internal/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class Cache

public bool $use_igbinary;

protected int $error_count = 0;

public function __construct(Config $config)
{
$this->config = $config;
Expand Down Expand Up @@ -63,7 +65,7 @@ public function getItem(string $path)

// invalid cache data
if ($inflated === false) {
$this->deleteItem($path);
$this->handleInvalidCache($path);

return null;
}
Expand All @@ -77,14 +79,30 @@ public function getItem(string $path)
}

if ($unserialized === false) {
$this->deleteItem($path);
$this->handleInvalidCache($path);

return null;
}

return $unserialized;
}

protected function handleInvalidCache(string $path): void
{
$this->deleteItem($path);

$this->error_count++;

// if 10 previous items were invalid, abort since the cache is invalid and inform the user
// we don't report it to the user immediately, since it can happen that a few files get corrupted somehow
// however the impact on performance is minimal, therefore we ignore it
if ($this->error_count > 10) {
throw new RuntimeException(
'The cache data is corrupted. Please delete the cache directory and run Psalm again',
);
}
}

public function deleteItem(string $path): void
{
if (file_exists($path)) {
Expand Down