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

Removed required argument for config, now handled by conversions, not a option means required

parent e3964450
......@@ -133,11 +133,12 @@ class Config(var map: Map[String, Any]) extends Logging {
*/
protected[config] def apply(module: String, path: List[String], key: String, default: Any = null, freeVar: Boolean = true): ConfigValue = {
val requestedIndex = ConfigValueIndex(module, path, key, freeVar)
if (contains(requestedIndex)) return foundCache(requestedIndex)
if (contains(requestedIndex)) foundCache(requestedIndex)
else if (default != null) {
defaultCache += (requestedIndex -> ConfigValue(requestedIndex, null, default, freeVar))
return defaultCache(requestedIndex)
} else throw new IllegalStateException("Value in config could not be found but it seems required, index: " + requestedIndex)
defaultCache(requestedIndex)
} else ConfigValue(requestedIndex, null, null, freeVar)
//else throw new IllegalStateException("Value in config could not be found but it seems required, index: " + requestedIndex)
}
def writeReport(id: String, directory: String): Unit = {
......
......@@ -79,7 +79,6 @@ trait Configurable extends ImplicitConversions {
* @param key Name of value
* @param default Default value if not found
* @param submodule Adds to the path
* @param required Default false, if true and value is not found this function will raise an exception
* @param freeVar Default true, if set false value must exist in module
* @param sample Default null, when set path is prefixed with "samples" -> "sampleID"
* @param library Default null, when set path is prefixed with "libraries" -> "libraryID"
......@@ -88,7 +87,6 @@ trait Configurable extends ImplicitConversions {
def apply(key: String,
default: Any = null,
submodule: String = null,
required: Boolean = false,
freeVar: Boolean = true,
sample: String = null,
library: String = null): ConfigValue = {
......@@ -100,14 +98,8 @@ trait Configurable extends ImplicitConversions {
val value = Config.getValueFromMap(defaults.toMap, ConfigValueIndex(m, p, key, freeVar))
if (value.isDefined) value.get.value else default
}
if (!contains(key, submodule, freeVar, sample = s, library = l) && d == null) {
if (required) {
Logging.logger.error("Value in config could not be found but it is required, key: " + key + " module: " + m + " path: " + p)
throw new IllegalStateException("Value in config could not be found but it is required, key: " + key + " module: " + m + " path: " + p)
} else return null
}
if (d == null) return Config.global(m, p, key, freeVar = freeVar)
else return Config.global(m, p, key, d, freeVar)
if (d == null) Config.global(m, p, key, freeVar = freeVar)
else Config.global(m, p, key, d, freeVar)
}
/**
......
......@@ -332,7 +332,9 @@ object ConfigUtils extends Logging {
private def requiredValue(value: ConfigValue): Unit = {
if (!valueExists(value))
throw new IllegalStateException("Value does not exist but is required, key: '" + value.requestIndex.key + "'")
throw new IllegalStateException("Value does not exist but is required, key: " + value.requestIndex.key +
" module: " + value.requestIndex.module +
(if (value.requestIndex.path != Nil) " path: " + value.requestIndex.path.mkString("->") else ""))
}
private def valueExists(value: ConfigValue): Boolean = {
......
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