From b2c98464ddbcc49533c1e0d90b5a4edda50e4673 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Tue, 16 Jan 2024 14:28:21 +0100 Subject: [PATCH] BUGFIX: Fusion avoid error parser cache to crash if cache is broken Resolves #4595 --- .../Classes/Core/Cache/ParserCache.php | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Neos.Fusion/Classes/Core/Cache/ParserCache.php b/Neos.Fusion/Classes/Core/Cache/ParserCache.php index 08f2a82b21a..2a4a483b4cb 100644 --- a/Neos.Fusion/Classes/Core/Cache/ParserCache.php +++ b/Neos.Fusion/Classes/Core/Cache/ParserCache.php @@ -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. @@ -42,6 +44,12 @@ class ParserCache */ protected $packageManager; + /** + * @Flow\Inject + * @var LoggerInterface + */ + protected $logger; + /** * @Flow\InjectConfiguration(path="enableParsePartialsCache") */ @@ -59,7 +67,18 @@ public function cacheForFusionFile(?string $contextPathAndFilename, \Closure $ge $contextPathAndFilename = $this->getAbsolutePathForPackageRessourceUri($contextPathAndFilename); } $identifier = $this->getCacheIdentifierForFile($contextPathAndFilename); - 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