Fix config import error handling

This commit is contained in:
Christian Duerr authored and GitHub committed 2020-08-22 00:38:09 +00:00
1 parent 3c3e6870de
commit 92a3d482d0
1 file changed
+12 -5
+12 -5
View File
@@ -191,24 +191,31 @@ fn parse_config(
/// Load all referenced configuration files.
fn load_imports(config: &Value, config_paths: &mut Vec<PathBuf>, recursion_limit: usize) -> Value {
let mut merged = Value::Null;
let imports = match config.get("import") {
Some(Value::Sequence(imports)) => imports,
_ => return merged,
Some(_) => {
error!(target: LOG_TARGET_CONFIG, "Invalid import type: expected a sequence");
return Value::Null;
},
None => return Value::Null,
};
// Limit recursion to prevent infinite loops.
if !imports.is_empty() && recursion_limit == 0 {
error!(target: LOG_TARGET_CONFIG, "Exceeded maximum configuration import depth");
return merged;
return Value::Null;
}
let mut merged = Value::Null;
for import in imports {
let path = match import {
Value::String(path) => PathBuf::from(path),
_ => {
error!(target: LOG_TARGET_CONFIG, "Encountered invalid configuration file import");
error!(
target: LOG_TARGET_CONFIG,
"Invalid import element type: expected path string"
);
continue;
},
};