From e92d88df8b10311fe9448f5c2bc26562f63bc3d7 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Thu, 12 Nov 2020 13:35:36 +0200 Subject: [PATCH] Fixed fatal error in `CompiledFile` if the cached version is broken --- CHANGELOG.md | 1 + system/src/Grav/Common/File/CompiledFile.php | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 531772cd7..d25c5d2f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ * Fixed `header.admin.children_display_order` in Flex Pages to work just like with regular pages * Fixed `Utils::isFunctionDisabled()` method if there are spaces in `disable_functions` [#3023](https://github.com/getgrav/grav/issues/3023) * Fixed potential fatal error when creating flex index using cache [#3062](https://github.com/getgrav/grav/issues/3062) + * Fixed fatal error in `CompiledFile` if the cached version is broken # v1.7.0-rc.17 ## 10/07/2020 diff --git a/system/src/Grav/Common/File/CompiledFile.php b/system/src/Grav/Common/File/CompiledFile.php index 161e8b4ff..023eadfff 100644 --- a/system/src/Grav/Common/File/CompiledFile.php +++ b/system/src/Grav/Common/File/CompiledFile.php @@ -12,6 +12,7 @@ namespace Grav\Common\File; use Exception; use RocketTheme\Toolbox\File\PhpFile; use RuntimeException; +use Throwable; use function function_exists; use function get_class; @@ -36,9 +37,12 @@ trait CompiledFile $file = PhpFile::instance(CACHE_DIR . "compiled/files/{$key}{$this->extension}.php"); $modified = $this->modified(); - if (!$modified) { - return $this->decode($this->raw()); + try { + return $this->decode($this->raw()); + } catch (Throwable $e) { + // If the compiled file is broken, we can safely ignore the error and continue. + } } $class = get_class($this);