Skip to content

Commit

Permalink
add back invalid cache reporting
Browse files Browse the repository at this point in the history
which was removed in vimeo#9889 - now we won't report for every error but if there are at least 10 errors (chosen arbitrarily)
  • Loading branch information
kkmuffme committed Jun 13, 2023
1 parent ad3fac9 commit 49fc00e
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/Psalm/Internal/Cache.php
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

0 comments on commit 49fc00e

Please sign in to comment.