neighbor/Glue: mention failed plugin name in error message

This commit is contained in:
Max Kellermann 2021-10-19 13:26:31 +02:00
parent 070c03dbf7
commit a8087dc12c
3 changed files with 19 additions and 8 deletions

2
NEWS
View File

@ -1,4 +1,6 @@
ver 0.23.2 (not yet released)
* neighbor
- mention failed plugin name in error message
ver 0.23.1 (2021/10/19)
* protocol

View File

@ -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;
}
}

View File

@ -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;
};