Commit e3964450 authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Fix for error handling

parent 4bf8722f
......@@ -330,14 +330,23 @@ object ConfigUtils extends Logging {
trait 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
* @param value Input ConfigValue
* @return
*/
implicit def configValue2file(value: ConfigValue): File = {
if (value != null && value.value != null && value.value != None) new File(any2string(value.value))
else throw new IllegalStateException("Value does not exist")
requiredValue(value)
new File(any2string(value.value))
}
/**
......@@ -346,7 +355,7 @@ object ConfigUtils extends Logging {
* @return
*/
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
}
......@@ -356,8 +365,8 @@ object ConfigUtils extends Logging {
* @return
*/
implicit def configValue2string(value: ConfigValue): String = {
if (value != null && value.value != null && value.value != None) any2string(value.value)
else throw new IllegalStateException("Value does not exist")
requiredValue(value)
any2string(value.value)
}
/**
......@@ -366,7 +375,7 @@ object ConfigUtils extends Logging {
* @return
*/
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
}
......@@ -376,8 +385,8 @@ object ConfigUtils extends Logging {
* @return
*/
implicit def configValue2long(value: ConfigValue): Long = {
if (value != null && value.value != null && value.value != None) any2long(value.value)
else throw new IllegalStateException("Value does not exist")
requiredValue(value)
any2long(value.value)
}
/**
......@@ -386,7 +395,7 @@ object ConfigUtils extends Logging {
* @return
*/
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
}
......@@ -396,8 +405,8 @@ object ConfigUtils extends Logging {
* @return
*/
implicit def configValue2int(value: ConfigValue): Int = {
if (value != null && value.value != null && value.value != None) any2int(value.value)
else throw new IllegalStateException("Value does not exist")
requiredValue(value)
any2int(value.value)
}
/**
......@@ -406,7 +415,7 @@ object ConfigUtils extends Logging {
* @return
*/
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
}
......@@ -416,8 +425,8 @@ object ConfigUtils extends Logging {
* @return
*/
implicit def configValue2double(value: ConfigValue): Double = {
if (value != null && value.value != null && value.value != None) any2double(value.value)
else throw new IllegalStateException("Value does not exist")
requiredValue(value)
any2double(value.value)
}
/**
......@@ -426,7 +435,7 @@ object ConfigUtils extends Logging {
* @return
*/
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
}
......@@ -436,8 +445,8 @@ object ConfigUtils extends Logging {
* @return
*/
implicit def configValue2float(value: ConfigValue): Float = {
if (value != null && value.value != null && value.value != None) any2float(value.value)
else throw new IllegalStateException("Value does not exist")
requiredValue(value)
any2float(value.value)
}
/**
......@@ -446,7 +455,7 @@ object ConfigUtils extends Logging {
* @return
*/
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
}
......@@ -456,8 +465,8 @@ object ConfigUtils extends Logging {
* @return
*/
implicit def configValue2boolean(value: ConfigValue): Boolean = {
if (value != null && value.value != null && value.value != None) any2boolean(value.value)
else throw new IllegalStateException("Value does not exist")
requiredValue(value)
any2boolean(value.value)
}
/**
......@@ -466,7 +475,7 @@ object ConfigUtils extends Logging {
* @return
*/
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
}
......@@ -476,8 +485,8 @@ object ConfigUtils extends Logging {
* @return
*/
implicit def configValue2list(value: ConfigValue): List[Any] = {
if (value != null && value.value != null && value.value != None) any2list(value.value)
else throw new IllegalStateException("Value does not exist")
requiredValue(value)
any2list(value.value)
}
/**
......@@ -486,8 +495,8 @@ object ConfigUtils extends Logging {
* @return
*/
implicit def configValue2stringList(value: ConfigValue): List[String] = {
if (value != null && value.value != null && value.value != None) any2stringList(value.value)
else throw new IllegalStateException("Value does not exist")
requiredValue(value)
any2stringList(value.value)
}
/**
......@@ -496,8 +505,8 @@ object ConfigUtils extends Logging {
* @return
*/
implicit def configValue2stringSet(value: ConfigValue): Set[String] = {
if (value != null && value.value != null && value.value != None) any2stringList(value.value).toSet
else throw new IllegalStateException("Value does not exist")
requiredValue(value)
any2stringList(value.value).toSet
}
/**
......@@ -506,8 +515,8 @@ object ConfigUtils extends Logging {
* @return
*/
implicit def configValue2map(value: ConfigValue): Map[String, Any] = {
if (value != null && value.value != null && value.value != None) any2map(value.value)
else throw new IllegalStateException("Value does not exist")
requiredValue(value)
any2map(value.value)
}
}
}
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