plugins: make logging on error more verbose

ref #3874
This commit is contained in:
Vaxry
2023-11-17 22:22:31 +00:00
parent db8f13291a
commit 51282f964f
3 changed files with 26 additions and 17 deletions

View File

@@ -10,7 +10,10 @@ CPluginSystem::CPluginSystem() {
CPlugin* CPluginSystem::loadPlugin(const std::string& path) {
m_szLastError = "";
if (getPluginByPath(path)) {
m_szLastError = "Cannot load a plugin twice!";
Debug::log(ERR, " [PluginSystem] Cannot load a plugin twice!");
return nullptr;
}
@@ -22,6 +25,7 @@ CPlugin* CPluginSystem::loadPlugin(const std::string& path) {
HANDLE MODULE = dlopen(path.c_str(), RTLD_LAZY);
if (!MODULE) {
m_szLastError = std::format("Plugin {} could not be loaded: {}", path, dlerror());
Debug::log(ERR, " [PluginSystem] Plugin {} could not be loaded: {}", path, dlerror());
m_vLoadedPlugins.pop_back();
return nullptr;
@@ -33,6 +37,7 @@ CPlugin* CPluginSystem::loadPlugin(const std::string& path) {
PPLUGIN_INIT_FUNC initFunc = (PPLUGIN_INIT_FUNC)dlsym(MODULE, PLUGIN_INIT_FUNC_STR);
if (!apiVerFunc || !initFunc) {
m_szLastError = std::format("Plugin {} could not be loaded: {}", path, "missing apiver/init func");
Debug::log(ERR, " [PluginSystem] Plugin {} could not be loaded. (No apiver/init func)", path);
dlclose(MODULE);
m_vLoadedPlugins.pop_back();
@@ -42,6 +47,7 @@ CPlugin* CPluginSystem::loadPlugin(const std::string& path) {
const std::string PLUGINAPIVER = apiVerFunc();
if (PLUGINAPIVER != HYPRLAND_API_VERSION) {
m_szLastError = std::format("Plugin {} could not be loaded: {}", path, "API version mismatch");
Debug::log(ERR, " [PluginSystem] Plugin {} could not be loaded. (API version mismatch)", path);
dlclose(MODULE);
m_vLoadedPlugins.pop_back();
@@ -56,10 +62,11 @@ CPlugin* CPluginSystem::loadPlugin(const std::string& path) {
PLUGINDATA = initFunc(MODULE);
} else {
// this module crashed.
throw std::exception();
throw std::runtime_error("received a fatal signal");
}
} catch (std::exception& e) {
m_bAllowConfigVars = false;
m_szLastError = std::format("Plugin {} could not be loaded: plugin crashed/threw in main: {}", path, e.what());
Debug::log(ERR, " [PluginSystem] Plugin {} (Handle {:x}) crashed in init. Unloading.", path, (uintptr_t)MODULE);
unloadPlugin(PLUGIN, true); // Plugin could've already hooked/done something
return nullptr;