Commit a8087dc1 authored by Max Kellermann's avatar Max Kellermann

neighbor/Glue: mention failed plugin name in error message

parent 070c03db
ver 0.23.2 (not yet released)
* neighbor
- mention failed plugin name in error message
ver 0.23.1 (2021/10/19)
* protocol
......
......@@ -33,12 +33,9 @@ NeighborGlue::~NeighborGlue() noexcept = default;
static std::unique_ptr<NeighborExplorer>
CreateNeighborExplorer(EventLoop &loop, NeighborListener &listener,
const char *plugin_name,
const ConfigBlock &block)
{
const char *plugin_name = block.GetBlockValue("plugin");
if (plugin_name == nullptr)
throw std::runtime_error("Missing \"plugin\" configuration");
const NeighborPlugin *plugin = GetNeighborPluginByName(plugin_name);
if (plugin == nullptr)
throw FormatRuntimeError("No such neighbor plugin: %s",
......@@ -55,8 +52,14 @@ NeighborGlue::Init(const ConfigData &config,
block.SetUsed();
try {
explorers.emplace_front(CreateNeighborExplorer(loop,
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: ",
......@@ -76,6 +79,9 @@ NeighborGlue::Open()
/* roll back */
for (auto k = explorers.begin(); k != i; ++k)
k->explorer->Close();
std::throw_with_nested(FormatRuntimeError("Failed to open neighblor plugin '%s'",
i->name.c_str()));
throw;
}
}
......
......@@ -24,6 +24,7 @@
#include <forward_list>
#include <memory>
#include <string>
struct ConfigData;
class EventLoop;
......@@ -36,11 +37,13 @@ struct NeighborInfo;
*/
class NeighborGlue {
struct Explorer {
const std::string name;
std::unique_ptr<NeighborExplorer> explorer;
template<typename E>
Explorer(E &&_explorer) noexcept
:explorer(std::forward<E>(_explorer)) {}
template<typename N, typename E>
Explorer(N &&_name, E &&_explorer) noexcept
:name(std::forward<N>(_name)),
explorer(std::forward<E>(_explorer)) {}
Explorer(const Explorer &) = delete;
};
......
Markdown is supported
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