Due to a scheduled upgrade to version 14.10, GitLab will be unavailabe on Monday 30.05., from 19:00 until 20:00.

Commit e78a4144 authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Improve exception handling

To make it clearer what went wrong.
parent 6640e2bd
...@@ -18,4 +18,11 @@ ...@@ -18,4 +18,11 @@
package org.memobase package org.memobase
class MissingSettingException(setting: String) : Exception("Missing setting $setting in configuration file. Stopping application ...") class MissingSettingException(source: String, setting: String) :
Exception(
when (source) {
"env" -> "Internal Configuration Error: $setting!"
"missing" -> "Internal Configuration Error: Missing setting $setting in configuration file."
else -> "User Configuration Error: A value for setting $setting is required."
}
)
...@@ -45,8 +45,7 @@ class SettingsLoader { ...@@ -45,8 +45,7 @@ class SettingsLoader {
load.loadFromInputStream(ClassLoader.getSystemResourceAsStream("app.yml")) load.loadFromInputStream(ClassLoader.getSystemResourceAsStream("app.yml"))
} }
} catch (ex: MissingEnvironmentVariableException) { } catch (ex: MissingEnvironmentVariableException) {
log.error(ex.message) throw MissingSettingException("env", "${ex.localizedMessage}")
exitProcess(1)
} }
} }
...@@ -57,14 +56,14 @@ class SettingsLoader { ...@@ -57,14 +56,14 @@ class SettingsLoader {
val kafkaProducerProperties = Properties() val kafkaProducerProperties = Properties()
init { init {
val rawYaml = loadYaml()
try { try {
val rawYaml = loadYaml()
val mappedYaml = rawYaml as Map<String, Any> val mappedYaml = rawYaml as Map<String, Any>
val kafkaOptions = mappedYaml["kafka"] as Map<String, Any> val kafkaOptions = mappedYaml["kafka"] as Map<String, Any>
val topics = kafkaOptions["topic"] as Map<String, String> val topics = kafkaOptions["topic"] as Map<String, String>
topic = topics["out"].orEmpty() topic = topics["out"].orEmpty()
if (topic.isEmpty()) { if (topic.isEmpty()) {
throw MissingSettingException("kafka.topic.out") throw MissingSettingException("missing", "kafka.topic.out")
} }
rawKafkaProperties = kafkaOptions["producer"] as Map<String, String> rawKafkaProperties = kafkaOptions["producer"] as Map<String, String>
...@@ -90,7 +89,7 @@ class SettingsLoader { ...@@ -90,7 +89,7 @@ class SettingsLoader {
private fun ensurePropertyIsSet(setting: String, settings: Map<String, String>) { private fun ensurePropertyIsSet(setting: String, settings: Map<String, String>) {
if (settings[setting].isNullOrEmpty()) { if (settings[setting].isNullOrEmpty()) {
throw MissingSettingException(setting) throw MissingSettingException("missing", setting)
} }
} }
...@@ -145,7 +144,7 @@ class SettingsLoader { ...@@ -145,7 +144,7 @@ class SettingsLoader {
} }
abortIfMissing -> { abortIfMissing -> {
log.error("Required producer property $propertyName was not set! Aborting...") log.error("Required producer property $propertyName was not set! Aborting...")
exitProcess(1) throw MissingSettingException("missing", "kafka.producer.$propertyName")
} }
else -> log.trace("No value for property $propertyName found") else -> log.trace("No value for property $propertyName found")
} }
......
...@@ -41,7 +41,7 @@ class SftpClient(sftpSettings: Map<String, String>) { ...@@ -41,7 +41,7 @@ class SftpClient(sftpSettings: Map<String, String>) {
ssh.authPassword(sftpSettings["user"], sftpSettings["password"]) ssh.authPassword(sftpSettings["user"], sftpSettings["password"])
instance = ssh.newSFTPClient() instance = ssh.newSFTPClient()
} catch (ex: UserAuthException) { } catch (ex: UserAuthException) {
log.error("Invalid user authentication supplied.") log.error("SFTP User Authentication Error: Invalid user authentication supplied.")
exitProcess(1) exitProcess(1)
} catch (ex: Exception) { } catch (ex: Exception) {
ex.printStackTrace() ex.printStackTrace()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment