mana auto replay: slightly improve plugin loading

it's still not great, error messages need to be better
This commit is contained in:
Florian Lüke 2024-12-30 03:24:33 +01:00
parent 0d862f401c
commit 0ef89eac14

View file

@ -438,28 +438,36 @@ int main(int argc, char *argv[])
try try
{ {
destSink = std::make_unique<mana::ManaCSink>( if (auto entryPoint =
pluginHandle.get<mana_sink_plugin_t()>("mana_get_sink_plugin")()); pluginHandle.get<mana_sink_plugin_t()>("mana_get_sink_plugin"))
{
destSink = std::make_unique<mana::ManaCSink>(entryPoint());
}
} }
catch (const std::exception &e) 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::IManaPlugin *()>("mana_get_plugin"))
{ {
manaCppPlugin = std::unique_ptr<mana::IManaPlugin>( manaCppPlugin = std::unique_ptr<mana::IManaPlugin>(entryPoint());
pluginHandle.get<mana::IManaPlugin *()>("mana_get_plugin")()); if (!manaCppPlugin)
throw std::runtime_error("plugin {}: mana_get_plugin() returned nullptr");
destSink = manaCppPlugin->makeSink(); 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) 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; return 1;
} }
} }