From 59a6f4be025d482d5d72d48a0ad8a1e8edb068a0 Mon Sep 17 00:00:00 2001
From: "stu126940@mail.uni-kiel.de" <stu126940@mail.uni-kiel.de>
Date: Wed, 2 Jun 2021 22:21:38 +0200
Subject: [PATCH] Throw DeploymentFailedException if patcher creating fails

---
 .../src/main/kotlin/theodolite/patcher/PatcherFactory.kt     | 5 ++++-
 .../main/kotlin/theodolite/util/DeploymentFailedException.kt | 5 +++++
 2 files changed, 9 insertions(+), 1 deletion(-)
 create mode 100644 theodolite-quarkus/src/main/kotlin/theodolite/util/DeploymentFailedException.kt

diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/patcher/PatcherFactory.kt b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/PatcherFactory.kt
index 9ca6570ff..58dd95e9d 100644
--- a/theodolite-quarkus/src/main/kotlin/theodolite/patcher/PatcherFactory.kt
+++ b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/PatcherFactory.kt
@@ -1,6 +1,7 @@
 package theodolite.patcher
 
 import io.fabric8.kubernetes.api.model.KubernetesResource
+import theodolite.util.DeploymentFailedException
 import theodolite.util.PatcherDefinition
 
 /**
@@ -27,7 +28,9 @@ class PatcherFactory {
         k8sResources: List<Pair<String, KubernetesResource>>
     ): Patcher {
         val resource =
-            k8sResources.filter { it.first == patcherDefinition.resource }.map { resource -> resource.second }[0]
+            k8sResources.filter { it.first == patcherDefinition.resource }.map { resource -> resource.second }.firstOrNull()
+                ?: throw DeploymentFailedException("Could not find resource ${patcherDefinition.resource}")
+
         return when (patcherDefinition.type) {
             "ReplicaPatcher" -> ReplicaPatcher(resource)
             "NumNestedGroupsLoadGeneratorReplicaPatcher" -> NumNestedGroupsLoadGeneratorReplicaPatcher(resource)
diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/util/DeploymentFailedException.kt b/theodolite-quarkus/src/main/kotlin/theodolite/util/DeploymentFailedException.kt
new file mode 100644
index 000000000..0e276d7de
--- /dev/null
+++ b/theodolite-quarkus/src/main/kotlin/theodolite/util/DeploymentFailedException.kt
@@ -0,0 +1,5 @@
+package theodolite.util
+
+
+class DeploymentFailedException(message:String): Exception(message) {
+}
\ No newline at end of file
-- 
GitLab