From 176ecc1ccd4a174908176766f4e874456923008e Mon Sep 17 00:00:00 2001 From: "stu126940@mail.uni-kiel.de" <stu126940@mail.uni-kiel.de> Date: Mon, 4 Oct 2021 10:36:28 +0200 Subject: [PATCH] Enhance exception handling --- .../kotlin/theodolite/benchmark/ConfigMapResourceSet.kt | 8 ++++---- .../kotlin/theodolite/benchmark/FileSystemResourceSet.kt | 8 ++++---- .../kotlin/theodolite/util/DeploymentFailedException.kt | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/theodolite/src/main/kotlin/theodolite/benchmark/ConfigMapResourceSet.kt b/theodolite/src/main/kotlin/theodolite/benchmark/ConfigMapResourceSet.kt index ba50ee016..1f89549fb 100644 --- a/theodolite/src/main/kotlin/theodolite/benchmark/ConfigMapResourceSet.kt +++ b/theodolite/src/main/kotlin/theodolite/benchmark/ConfigMapResourceSet.kt @@ -36,9 +36,9 @@ class ConfigMapResourceSet: ResourceSet, KubernetesResource { .data .filter { it.key.endsWith(".yaml") } // consider only yaml files, e.g. ignore readme files } catch (e: KubernetesClientException) { - throw DeploymentFailedException("can not find or read configmap: $name, error is: ${e.message}") + throw DeploymentFailedException("can not find or read configmap: $name", e) } catch (e: IllegalStateException) { - throw DeploymentFailedException("can not find configmap or data section is null $name, error is: ${e.message}") + throw DeploymentFailedException("can not find configmap or data section is null $name", e) } if (::files.isInitialized){ @@ -56,7 +56,7 @@ class ConfigMapResourceSet: ResourceSet, KubernetesResource { it.second.key, loader.loadK8sResource(it.first, it.second.value)) } } catch (e: IllegalArgumentException) { - throw DeploymentFailedException("Can not creat resource set from specified configmap" + e.message) + throw DeploymentFailedException("Can not creat resource set from specified configmap", e) } } @@ -68,7 +68,7 @@ class ConfigMapResourceSet: ResourceSet, KubernetesResource { return try { resourceAsMap?.get("kind") !! } catch (e: NullPointerException) { - throw DeploymentFailedException( "Could not find field kind of Kubernetes resource: ${resourceAsMap?.get("name")}" ) + throw DeploymentFailedException( "Could not find field kind of Kubernetes resource: ${resourceAsMap?.get("name")}", e) } } } \ No newline at end of file diff --git a/theodolite/src/main/kotlin/theodolite/benchmark/FileSystemResourceSet.kt b/theodolite/src/main/kotlin/theodolite/benchmark/FileSystemResourceSet.kt index 723f81cf1..92df1bec3 100644 --- a/theodolite/src/main/kotlin/theodolite/benchmark/FileSystemResourceSet.kt +++ b/theodolite/src/main/kotlin/theodolite/benchmark/FileSystemResourceSet.kt @@ -37,7 +37,7 @@ class FileSystemResourceSet: ResourceSet, KubernetesResource { loadSingleResource(resourceURL = it, client = client) } } catch (e: NullPointerException) { - throw DeploymentFailedException("Could not load files located in $path, error is: ${e.message}") + throw DeploymentFailedException("Could not load files located in $path", e) } } @@ -50,9 +50,9 @@ class FileSystemResourceSet: ResourceSet, KubernetesResource { try { kind = parser.parse(resourcePath, HashMap<String, String>()::class.java)?.get("kind")!! } catch (e: NullPointerException) { - throw DeploymentFailedException("Can not get Kind from resource $resourcePath, error is ${e.message}") + throw DeploymentFailedException("Can not get Kind from resource $resourcePath", e) } catch (e: FileNotFoundException){ - throw DeploymentFailedException("File $resourcePath not found") + throw DeploymentFailedException("File $resourcePath not found", e) } @@ -60,7 +60,7 @@ class FileSystemResourceSet: ResourceSet, KubernetesResource { val k8sResource = loader.loadK8sResource(kind, resourcePath) Pair(resourceURL, k8sResource) } catch (e: IllegalArgumentException) { - throw DeploymentFailedException("Could not load resource: $resourcePath, caused by exception: ${e.message}") + throw DeploymentFailedException("Could not load resource: $resourcePath", e) } } } \ No newline at end of file diff --git a/theodolite/src/main/kotlin/theodolite/util/DeploymentFailedException.kt b/theodolite/src/main/kotlin/theodolite/util/DeploymentFailedException.kt index 639a7c86c..9439024ee 100644 --- a/theodolite/src/main/kotlin/theodolite/util/DeploymentFailedException.kt +++ b/theodolite/src/main/kotlin/theodolite/util/DeploymentFailedException.kt @@ -1,4 +1,4 @@ package theodolite.util -class DeploymentFailedException(message: String) : Exception(message) \ No newline at end of file +class DeploymentFailedException(message: String, e: Exception? = null): Exception(message, e) \ No newline at end of file -- GitLab