diff --git a/src/Cache/FileCacheStorage.php b/src/Cache/FileCacheStorage.php index c5597e51ce..d930f78a41 100644 --- a/src/Cache/FileCacheStorage.php +++ b/src/Cache/FileCacheStorage.php @@ -77,11 +77,17 @@ public function save(string $key, string $variableKey, $data): void $this->makeDir($secondDirectory); $tmpPath = sprintf('%s/%s.tmp', $this->directory, Random::generate()); + $errorBefore = error_get_last(); + $exported = @var_export(new CacheItem($variableKey, $data), true); + $errorAfter = error_get_last(); + if ($errorAfter !== null && $errorBefore !== $errorAfter) { + throw new \PHPStan\ShouldNotHappenException(sprintf('Error occurred while saving item %s (%s) to cache: %s', $key, $variableKey, $errorAfter['message'])); + } FileWriter::write( $tmpPath, sprintf( "