diff options
author | Vaxry <[email protected]> | 2023-11-17 22:22:31 +0000 |
---|---|---|
committer | Vaxry <[email protected]> | 2023-11-17 22:22:31 +0000 |
commit | 51282f964f0bbf8e04fb3a62435a4e925b8945ed (patch) | |
tree | cc6ba659468d53d8b72a85e23bb20df407541f1a /src/plugins | |
parent | db8f13291a4e046e82c9b11c5bfd08f223bd52b1 (diff) | |
download | Hyprland-51282f964f0bbf8e04fb3a62435a4e925b8945ed.tar.gz Hyprland-51282f964f0bbf8e04fb3a62435a4e925b8945ed.zip |
plugins: make logging on error more verbose
ref #3874
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/PluginSystem.cpp | 9 | ||||
-rw-r--r-- | src/plugins/PluginSystem.hpp | 1 |
2 files changed, 9 insertions, 1 deletions
diff --git a/src/plugins/PluginSystem.cpp b/src/plugins/PluginSystem.cpp index a8ab904c..07dd226c 100644 --- a/src/plugins/PluginSystem.cpp +++ b/src/plugins/PluginSystem.cpp @@ -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; diff --git a/src/plugins/PluginSystem.hpp b/src/plugins/PluginSystem.hpp index 0ef30bab..f0c9c9ad 100644 --- a/src/plugins/PluginSystem.hpp +++ b/src/plugins/PluginSystem.hpp @@ -38,6 +38,7 @@ class CPluginSystem { std::vector<CPlugin*> getAllPlugins(); bool m_bAllowConfigVars = false; + std::string m_szLastError = ""; private: std::vector<std::unique_ptr<CPlugin>> m_vLoadedPlugins; |