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 @@
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 {
load.loadFromInputStream(ClassLoader.getSystemResourceAsStream("app.yml"))
}
} catch (ex: MissingEnvironmentVariableException) {
log.error(ex.message)
exitProcess(1)
throw MissingSettingException("env", "${ex.localizedMessage}")
}
}
......@@ -57,14 +56,14 @@ class SettingsLoader {
val kafkaProducerProperties = Properties()
init {
val rawYaml = loadYaml()
try {
val rawYaml = loadYaml()
val mappedYaml = rawYaml as Map<String, Any>
val kafkaOptions = mappedYaml["kafka"] as Map<String, Any>
val topics = kafkaOptions["topic"] as Map<String, String>
topic = topics["out"].orEmpty()
if (topic.isEmpty()) {
throw MissingSettingException("kafka.topic.out")
throw MissingSettingException("missing", "kafka.topic.out")
}
rawKafkaProperties = kafkaOptions["producer"] as Map<String, String>
......@@ -90,7 +89,7 @@ class SettingsLoader {
private fun ensurePropertyIsSet(setting: String, settings: Map<String, String>) {
if (settings[setting].isNullOrEmpty()) {
throw MissingSettingException(setting)
throw MissingSettingException("missing", setting)
}
}
......@@ -145,7 +144,7 @@ class SettingsLoader {
}
abortIfMissing -> {
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")
}
......
......@@ -41,7 +41,7 @@ class SftpClient(sftpSettings: Map<String, String>) {
ssh.authPassword(sftpSettings["user"], sftpSettings["password"])
instance = ssh.newSFTPClient()
} catch (ex: UserAuthException) {
log.error("Invalid user authentication supplied.")
log.error("SFTP User Authentication Error: Invalid user authentication supplied.")
exitProcess(1)
} catch (ex: Exception) {
ex.printStackTrace()
......
Supports Markdown
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