Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
memoriav
Memobase 2020
services
Import Process
Text File Validation
Commits
e78a4144
Commit
e78a4144
authored
Apr 07, 2020
by
Jonas Waeber
Browse files
Improve exception handling
To make it clearer what went wrong.
parent
6640e2bd
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/main/kotlin/MissingSettingException.kt
View file @
e78a4144
...
...
@@ -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."
}
)
src/main/kotlin/SettingsLoader.kt
View file @
e78a4144
...
...
@@ -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"
)
}
...
...
src/main/kotlin/SftpClient.kt
View file @
e78a4144
...
...
@@ -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
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment