Skip to content
Snippets Groups Projects
Commit e3964450 authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Fix for error handling

parent 4bf8722f
No related branches found
No related tags found
No related merge requests found
...@@ -330,14 +330,23 @@ object ConfigUtils extends Logging { ...@@ -330,14 +330,23 @@ object ConfigUtils extends Logging {
trait ImplicitConversions { trait ImplicitConversions {
import scala.language.implicitConversions import scala.language.implicitConversions
private def requiredValue(value: ConfigValue): Unit = {
if (!valueExists(value))
throw new IllegalStateException("Value does not exist but is required, key: '" + value.requestIndex.key + "'")
}
private def valueExists(value: ConfigValue): Boolean = {
value != null && value.value != null && value.value != None
}
/** /**
* Convert ConfigValue to File * Convert ConfigValue to File
* @param value Input ConfigValue * @param value Input ConfigValue
* @return * @return
*/ */
implicit def configValue2file(value: ConfigValue): File = { implicit def configValue2file(value: ConfigValue): File = {
if (value != null && value.value != null && value.value != None) new File(any2string(value.value)) requiredValue(value)
else throw new IllegalStateException("Value does not exist") new File(any2string(value.value))
} }
/** /**
...@@ -346,7 +355,7 @@ object ConfigUtils extends Logging { ...@@ -346,7 +355,7 @@ object ConfigUtils extends Logging {
* @return * @return
*/ */
implicit def configValue2optionFile(value: ConfigValue): Option[File] = { implicit def configValue2optionFile(value: ConfigValue): Option[File] = {
if (value != null && value.value != null && value.value != None) Some(new File(any2string(value.value))) if (valueExists(value)) Some(new File(any2string(value.value)))
else None else None
} }
...@@ -356,8 +365,8 @@ object ConfigUtils extends Logging { ...@@ -356,8 +365,8 @@ object ConfigUtils extends Logging {
* @return * @return
*/ */
implicit def configValue2string(value: ConfigValue): String = { implicit def configValue2string(value: ConfigValue): String = {
if (value != null && value.value != null && value.value != None) any2string(value.value) requiredValue(value)
else throw new IllegalStateException("Value does not exist") any2string(value.value)
} }
/** /**
...@@ -366,7 +375,7 @@ object ConfigUtils extends Logging { ...@@ -366,7 +375,7 @@ object ConfigUtils extends Logging {
* @return * @return
*/ */
implicit def configValue2optionString(value: ConfigValue): Option[String] = { implicit def configValue2optionString(value: ConfigValue): Option[String] = {
if (value != null && value.value != null && value.value != None) Some(any2string(value.value)) if (valueExists(value)) Some(any2string(value.value))
else None else None
} }
...@@ -376,8 +385,8 @@ object ConfigUtils extends Logging { ...@@ -376,8 +385,8 @@ object ConfigUtils extends Logging {
* @return * @return
*/ */
implicit def configValue2long(value: ConfigValue): Long = { implicit def configValue2long(value: ConfigValue): Long = {
if (value != null && value.value != null && value.value != None) any2long(value.value) requiredValue(value)
else throw new IllegalStateException("Value does not exist") any2long(value.value)
} }
/** /**
...@@ -386,7 +395,7 @@ object ConfigUtils extends Logging { ...@@ -386,7 +395,7 @@ object ConfigUtils extends Logging {
* @return * @return
*/ */
implicit def configValue2optionLong(value: ConfigValue): Option[Long] = { implicit def configValue2optionLong(value: ConfigValue): Option[Long] = {
if (value != null && value.value != null && value.value != None) Option(any2long(value.value)) if (valueExists(value)) Option(any2long(value.value))
else None else None
} }
...@@ -396,8 +405,8 @@ object ConfigUtils extends Logging { ...@@ -396,8 +405,8 @@ object ConfigUtils extends Logging {
* @return * @return
*/ */
implicit def configValue2int(value: ConfigValue): Int = { implicit def configValue2int(value: ConfigValue): Int = {
if (value != null && value.value != null && value.value != None) any2int(value.value) requiredValue(value)
else throw new IllegalStateException("Value does not exist") any2int(value.value)
} }
/** /**
...@@ -406,7 +415,7 @@ object ConfigUtils extends Logging { ...@@ -406,7 +415,7 @@ object ConfigUtils extends Logging {
* @return * @return
*/ */
implicit def configValue2optionInt(value: ConfigValue): Option[Int] = { implicit def configValue2optionInt(value: ConfigValue): Option[Int] = {
if (value != null && value.value != null && value.value != None) Option(any2int(value.value)) if (valueExists(value)) Option(any2int(value.value))
else None else None
} }
...@@ -416,8 +425,8 @@ object ConfigUtils extends Logging { ...@@ -416,8 +425,8 @@ object ConfigUtils extends Logging {
* @return * @return
*/ */
implicit def configValue2double(value: ConfigValue): Double = { implicit def configValue2double(value: ConfigValue): Double = {
if (value != null && value.value != null && value.value != None) any2double(value.value) requiredValue(value)
else throw new IllegalStateException("Value does not exist") any2double(value.value)
} }
/** /**
...@@ -426,7 +435,7 @@ object ConfigUtils extends Logging { ...@@ -426,7 +435,7 @@ object ConfigUtils extends Logging {
* @return * @return
*/ */
implicit def configValue2optionDouble(value: ConfigValue): Option[Double] = { implicit def configValue2optionDouble(value: ConfigValue): Option[Double] = {
if (value != null && value.value != null && value.value != None) Option(any2double(value.value)) if (valueExists(value)) Option(any2double(value.value))
else None else None
} }
...@@ -436,8 +445,8 @@ object ConfigUtils extends Logging { ...@@ -436,8 +445,8 @@ object ConfigUtils extends Logging {
* @return * @return
*/ */
implicit def configValue2float(value: ConfigValue): Float = { implicit def configValue2float(value: ConfigValue): Float = {
if (value != null && value.value != null && value.value != None) any2float(value.value) requiredValue(value)
else throw new IllegalStateException("Value does not exist") any2float(value.value)
} }
/** /**
...@@ -446,7 +455,7 @@ object ConfigUtils extends Logging { ...@@ -446,7 +455,7 @@ object ConfigUtils extends Logging {
* @return * @return
*/ */
implicit def configValue2optionFloat(value: ConfigValue): Option[Float] = { implicit def configValue2optionFloat(value: ConfigValue): Option[Float] = {
if (value != null && value.value != null && value.value != None) Option(any2float(value.value)) if (valueExists(value)) Option(any2float(value.value))
else None else None
} }
...@@ -456,8 +465,8 @@ object ConfigUtils extends Logging { ...@@ -456,8 +465,8 @@ object ConfigUtils extends Logging {
* @return * @return
*/ */
implicit def configValue2boolean(value: ConfigValue): Boolean = { implicit def configValue2boolean(value: ConfigValue): Boolean = {
if (value != null && value.value != null && value.value != None) any2boolean(value.value) requiredValue(value)
else throw new IllegalStateException("Value does not exist") any2boolean(value.value)
} }
/** /**
...@@ -466,7 +475,7 @@ object ConfigUtils extends Logging { ...@@ -466,7 +475,7 @@ object ConfigUtils extends Logging {
* @return * @return
*/ */
implicit def configValue2optionBoolean(value: ConfigValue): Option[Boolean] = { implicit def configValue2optionBoolean(value: ConfigValue): Option[Boolean] = {
if (value != null && value.value != null && value.value != None) Option(any2boolean(value.value)) if (valueExists(value)) Option(any2boolean(value.value))
else None else None
} }
...@@ -476,8 +485,8 @@ object ConfigUtils extends Logging { ...@@ -476,8 +485,8 @@ object ConfigUtils extends Logging {
* @return * @return
*/ */
implicit def configValue2list(value: ConfigValue): List[Any] = { implicit def configValue2list(value: ConfigValue): List[Any] = {
if (value != null && value.value != null && value.value != None) any2list(value.value) requiredValue(value)
else throw new IllegalStateException("Value does not exist") any2list(value.value)
} }
/** /**
...@@ -486,8 +495,8 @@ object ConfigUtils extends Logging { ...@@ -486,8 +495,8 @@ object ConfigUtils extends Logging {
* @return * @return
*/ */
implicit def configValue2stringList(value: ConfigValue): List[String] = { implicit def configValue2stringList(value: ConfigValue): List[String] = {
if (value != null && value.value != null && value.value != None) any2stringList(value.value) requiredValue(value)
else throw new IllegalStateException("Value does not exist") any2stringList(value.value)
} }
/** /**
...@@ -496,8 +505,8 @@ object ConfigUtils extends Logging { ...@@ -496,8 +505,8 @@ object ConfigUtils extends Logging {
* @return * @return
*/ */
implicit def configValue2stringSet(value: ConfigValue): Set[String] = { implicit def configValue2stringSet(value: ConfigValue): Set[String] = {
if (value != null && value.value != null && value.value != None) any2stringList(value.value).toSet requiredValue(value)
else throw new IllegalStateException("Value does not exist") any2stringList(value.value).toSet
} }
/** /**
...@@ -506,8 +515,8 @@ object ConfigUtils extends Logging { ...@@ -506,8 +515,8 @@ object ConfigUtils extends Logging {
* @return * @return
*/ */
implicit def configValue2map(value: ConfigValue): Map[String, Any] = { implicit def configValue2map(value: ConfigValue): Map[String, Any] = {
if (value != null && value.value != null && value.value != None) any2map(value.value) requiredValue(value)
else throw new IllegalStateException("Value does not exist") any2map(value.value)
} }
} }
} }
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