From 2d3ba9d186171683dfcf408a6e9e7fa721d2062d Mon Sep 17 00:00:00 2001
From: Bart Jaskulski <bjaskulski@protonmail.com>
Date: Thu, 5 Dec 2024 08:45:53 +0100
Subject: [PATCH] fix: prevent infinite loop on errors

Signed-off-by: Bart Jaskulski <bjaskulski@protonmail.com>
---
 src/Kernel.php | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/Kernel.php b/src/Kernel.php
index 0416c85..ffa5f98 100644
--- a/src/Kernel.php
+++ b/src/Kernel.php
@@ -92,10 +92,10 @@ final class Kernel {
 		return preg_replace( '/[^\w_]/', '_', implode("_", [ $plugin->get_slug(), $plugin->get_version(), 'container' ]) );
 	}
 
-	private function initialize_container( Plugin $plugin, bool $useCache = true ): Container {
+	private function initialize_container( Plugin $plugin, bool $use_cache = true ): Container {
 		$original_builder = new DiBuilder();
 
-		if ( $this->is_prod() && $useCache ) {
+		if ( $this->is_prod() && $use_cache ) {
 			$original_builder->enableCompilation(
 				$this->get_cache_path(),
 				$this->get_container_name( $plugin )
@@ -114,7 +114,12 @@ final class Kernel {
 
 		try {
 			return $builder->build();
-		} catch ( \Exception $e ) {
+		} catch ( \InvalidArgumentException $e ) {
+			if ( $use_cache === false ) {
+				// It means, that saving to disk was not an issue.
+				throw $e;
+			}
+
 			return $this->initialize_container( $plugin, false );
 		}
 	}
-- 
GitLab