From a8087dc12c4c23f510d16e4f3c564bcc68c794d0 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 19 Oct 2021 13:26:31 +0200 Subject: [PATCH] neighbor/Glue: mention failed plugin name in error message --- NEWS | 2 ++ src/neighbor/Glue.cxx | 16 +++++++++++----- src/neighbor/Glue.hxx | 9 ++++++--- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/NEWS b/NEWS index e0ce16000..6b36ece15 100644 --- a/NEWS +++ b/NEWS @@ -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 diff --git a/src/neighbor/Glue.cxx b/src/neighbor/Glue.cxx index 5da424b0a..4c6a08c9a 100644 --- a/src/neighbor/Glue.cxx +++ b/src/neighbor/Glue.cxx @@ -33,12 +33,9 @@ NeighborGlue::~NeighborGlue() noexcept = default; static std::unique_ptr 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; } } diff --git a/src/neighbor/Glue.hxx b/src/neighbor/Glue.hxx index a511c9afe..cf0c85576 100644 --- a/src/neighbor/Glue.hxx +++ b/src/neighbor/Glue.hxx @@ -24,6 +24,7 @@ #include #include +#include struct ConfigData; class EventLoop; @@ -36,11 +37,13 @@ struct NeighborInfo; */ class NeighborGlue { struct Explorer { + const std::string name; std::unique_ptr explorer; - template - Explorer(E &&_explorer) noexcept - :explorer(std::forward(_explorer)) {} + template + Explorer(N &&_name, E &&_explorer) noexcept + :name(std::forward(_name)), + explorer(std::forward(_explorer)) {} Explorer(const Explorer &) = delete; };