diff --git a/src/yamlconfig.cpp b/src/yamlconfig.cpp index 3e3f171..3f3a514 100644 --- a/src/yamlconfig.cpp +++ b/src/yamlconfig.cpp @@ -697,7 +697,6 @@ bool convert>::decode(const Node &node, wtf_ptr &config) throw ParserException(get_mark_compat(node), "Invalid YAML syntax"); config = make_wtf(); - vector> fan_configs; for (YAML::const_iterator it = node.begin(); it != node.end(); ++it) { const string key = it->first.as(); @@ -714,7 +713,6 @@ bool convert>::decode(const Node &node, wtf_ptr &config) throw YamlError(get_mark_compat(node), "Missing \"sensors:\" entry"); if (node[kw_fans]) { - vector> fans; try { // Each fan with its own levels section (supports multiple fans) for (auto fan_cfg : node[kw_fans].as>>()) { @@ -724,6 +722,8 @@ bool convert>::decode(const Node &node, wtf_ptr &config) } } catch (BadConversion &) { // Single fan entry with separate levels section below. + vector> fans; + if (node[kw_fans].size() > 1) throw YamlError(get_mark_compat(node[kw_fans]), "When multiple fans are configured, each must have its own 'levels:' section"); try { @@ -736,6 +736,12 @@ bool convert>::decode(const Node &node, wtf_ptr &config) } } + vector> fan_configs; + + for (unique_ptr &fan : fans) + fan_configs.push_back(std::make_unique(std::move(fan))); + fans.clear(); + if (node[kw_levels]) { // Separate "levels:" section if (config->fan_configs().size()) @@ -754,9 +760,6 @@ bool convert>::decode(const Node &node, wtf_ptr &config) throw YamlError(get_mark_compat(node), "Missing \"levels:\" entry"); } - for (unique_ptr &fan : fans) - fan_configs.push_back(std::make_unique(std::move(fan))); - fans.clear(); } else throw YamlError(get_mark_compat(node), "Missing \"fans:\" entry");