From b6b1cf6a45c51cce6616e41760b3e73249537e8a Mon Sep 17 00:00:00 2001 From: Priyadi Iman Nurcahyo <1102197+priyadi@users.noreply.github.com> Date: Mon, 15 Jan 2024 00:46:06 +0700 Subject: [PATCH] fix: Remove cache file & regenerate it if is corrupt. --- CHANGELOG.md | 1 + src/Mapping/CachingMappingFactory.php | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dbea4d1b..3b42a88c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ * style: Remove unused vars. * feat: Transformers now have the option to have an invariant target type. * fix: Wrong service id for `CopyTransformer`. +* fix: Remove cache file & regenerate it if it is corrupt. ## 0.5.8 diff --git a/src/Mapping/CachingMappingFactory.php b/src/Mapping/CachingMappingFactory.php index cda58822..93e93b97 100644 --- a/src/Mapping/CachingMappingFactory.php +++ b/src/Mapping/CachingMappingFactory.php @@ -51,8 +51,14 @@ public function getMapping(): Mapping return $this->warmUpAndGetMapping(); } - /** @psalm-suppress UnresolvableInclude */ - $result = require $this->getCacheFilePath(); + try { + /** @psalm-suppress UnresolvableInclude */ + $result = require $this->getCacheFilePath(); + } catch (\Throwable) { + unlink($this->getCacheFilePath()); + + return $this->warmUpAndGetMapping(); + } if (!$result instanceof Mapping) { unlink($this->getCacheFilePath());