Skip to content

Commit

Permalink
BUGFIX: Fusion avoid error parser cache to crash if cache is broken
Browse files Browse the repository at this point in the history
Resolves #4595
  • Loading branch information
mhsdesign committed Feb 2, 2024
1 parent 43d2f34 commit b4ac8e9
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion Neos.Fusion/Classes/Core/Cache/ParserCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@

use Neos\Flow\Annotations as Flow;
use Neos\Cache\Frontend\VariableFrontend;
use Neos\Flow\Log\Utility\LogEnvironment;
use Neos\Flow\Package\PackageManager;
use Neos\Fusion\Core\ObjectTreeParser\Ast\FusionFile;
use Neos\Utility\Unicode\Functions as UnicodeFunctions;
use Neos\Utility\Files;
use Psr\Log\LoggerInterface;

/**
* Helper around the ParsePartials Cache.
Expand All @@ -42,6 +44,12 @@ class ParserCache
*/
protected $packageManager;

/**
* @Flow\Inject
* @var LoggerInterface
*/
protected $logger;

/**
* @Flow\InjectConfiguration(path="enableParsePartialsCache")
*/
Expand All @@ -64,7 +72,18 @@ public function cacheForFusionFile(?string $contextPathAndFilename, \Closure $ge
throw new \RuntimeException("Couldn't resolve realpath for: '$contextPathAndFilename'", 1705409467);
}
$identifier = $this->getCacheIdentifierForAbsoluteUnixStyleFilePathWithoutDirectoryTraversal($fusionFileRealPath);
return $this->cacheForIdentifier($identifier, $generateValueToCache);
$value = $this->cacheForIdentifier($identifier, $generateValueToCache);
if (!$value instanceof FusionFile) {
$this->logger->error(sprintf(
'Unexpected cache error in parser cache while retrieving identifier %s. Expected cache %s with backend %s to return `FusionFile` but got `%s`.',
$identifier,
$this->parsePartialsCache->getIdentifier(),
get_class($this->parsePartialsCache->getBackend()),
get_debug_type($value)
), LogEnvironment::fromMethodName(__METHOD__));
return $generateValueToCache();
}
return $value;
}

public function cacheForDsl(string $identifier, string $code, \Closure $generateValueToCache): mixed
Expand Down

0 comments on commit b4ac8e9

Please sign in to comment.