Skip to content
Snippets Groups Projects
Commit 176ecc1c authored by Benedikt Wetzel's avatar Benedikt Wetzel
Browse files

Enhance exception handling

parent fe71adac
No related branches found
No related tags found
1 merge request!171Introduce ResourceSets to make loading of resource files more flexible
......@@ -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
......@@ -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
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment