config/Data: add WithEach(ConfigBlockOption)

To improve error messages without making callers more complex.
This commit is contained in:
Max Kellermann
2022-07-12 21:02:49 +02:00
parent 89a18b49a7
commit ae4f4d3533
5 changed files with 46 additions and 20 deletions

View File

@@ -48,24 +48,16 @@ void
NeighborGlue::Init(const ConfigData &config,
EventLoop &loop, NeighborListener &listener)
{
for (const auto &block : config.GetBlockList(ConfigBlockOption::NEIGHBORS)) {
block.SetUsed();
config.WithEach(ConfigBlockOption::NEIGHBORS, [&, this](const auto &block){
const char *plugin_name = block.GetBlockValue("plugin");
if (plugin_name == nullptr)
throw std::runtime_error("Missing \"plugin\" configuration");
try {
const char *plugin_name = block.GetBlockValue("plugin");
if (plugin_name == nullptr)
throw std::runtime_error("Missing \"plugin\" configuration");
explorers.emplace_front(plugin_name,
CreateNeighborExplorer(loop,
listener,
plugin_name,
block));
} catch (...) {
std::throw_with_nested(FormatRuntimeError("Line %i: ",
block.line));
}
}
explorers.emplace_front(plugin_name,
CreateNeighborExplorer(loop, listener,
plugin_name,
block));
});
}
void