From 0ef89eac1453b59866abb11b8b553c1c13da5e79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20L=C3=BCke?= Date: Mon, 30 Dec 2024 03:24:33 +0100 Subject: [PATCH] mana auto replay: slightly improve plugin loading it's still not great, error messages need to be better --- src/tools/mana_auto_replay.cc | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/tools/mana_auto_replay.cc b/src/tools/mana_auto_replay.cc index 97eae9f..b063e8e 100644 --- a/src/tools/mana_auto_replay.cc +++ b/src/tools/mana_auto_replay.cc @@ -438,28 +438,36 @@ int main(int argc, char *argv[]) try { - destSink = std::make_unique( - pluginHandle.get("mana_get_sink_plugin")()); + if (auto entryPoint = + pluginHandle.get("mana_get_sink_plugin")) + { + destSink = std::make_unique(entryPoint()); + } } catch (const std::exception &e) { - spdlog::debug("plugin {} is not a MANA_C_SINK_PLUGIN", pluginFile); - try + } + + if (!destSink) + { + if (auto entryPoint = pluginHandle.get("mana_get_plugin")) { - manaCppPlugin = std::unique_ptr( - pluginHandle.get("mana_get_plugin")()); + manaCppPlugin = std::unique_ptr(entryPoint()); + if (!manaCppPlugin) + throw std::runtime_error("plugin {}: mana_get_plugin() returned nullptr"); destSink = manaCppPlugin->makeSink(); } - catch (const std::exception &e) - { - std::cerr << fmt::format("Error loading plugin: {}\n", e.what()); - return 1; - } } } catch (const std::exception &e) { - std::cerr << fmt::format("Error loading plugin: {}\n", e.what()); + std::cerr << fmt::format("Error loading shared library {}: {}\n", pluginFile, e.what()); + return 1; + } + + if (!destSink) + { + std::cerr << fmt::format("Error: plugin {} does not provide a sink\n", pluginFile); return 1; } }