Skip to content

Commit dfcd512

Browse files
committed
feat(plugins-list): Show load error in sw plugins list
1 parent 9d7b4d2 commit dfcd512

File tree

5 files changed

+17
-1
lines changed

5 files changed

+17
-1
lines changed

src/components/BasicComponent/src/BasicComponent.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,14 @@ void SwiftlyPluginManagerList(CPlayerSlot *slot, CCommandContext context)
165165

166166
PrintToClientOrConsole(slot, "Plugins List", "Showing below %02d plugins loaded:\n", loadedPlugins);
167167
uint32 showingIdx = 0;
168+
std::vector<std::string> errors;
168169
for (uint32 i = 0; i < plugins.size(); i++)
169170
{
170171
Plugin *plugin = plugins[i];
171172
if (plugin == nullptr)
172173
continue;
174+
if (plugin->err.size() > 0)
175+
errors.push_back(string_format("Plugin '%s': %s", plugin->GetName().c_str(), plugin->err.c_str()));
173176
if (!plugin->IsPluginLoaded())
174177
continue;
175178

@@ -187,6 +190,14 @@ void SwiftlyPluginManagerList(CPlayerSlot *slot, CCommandContext context)
187190
plugin->ExecuteFunctionWithReturn<const char *, GetPlugin>("GetPluginAuthor"),
188191
website == "" ? "" : string_format(" ( %s )", website.c_str()).c_str());
189192
}
193+
if (errors.size() && slot->Get() == -1)
194+
{
195+
PrintToClientOrConsole(slot, "Plugins List", "Plugin load errors:\n");
196+
for (const std::string err : errors)
197+
PrintToClientOrConsole(slot, "Plugins List", "%s\n", err.c_str());
198+
199+
errors.clear();
200+
}
190201
}
191202

192203
void SwiftlyPluginManagerInfo(CPlayerSlot *slot, CCommandContext context, std::string plugin_name)

src/components/Plugins/inc/Plugin.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ class Plugin
154154
virtual bool InternalLoadPlugin() = 0;
155155

156156
public:
157+
std::string err;
157158
std::string m_path;
158159

159160
Plugin(std::string path, std::string name, PluginType_t pluginType) : m_path(path)
@@ -168,6 +169,8 @@ class Plugin
168169

169170
void LoadPlugin()
170171
{
172+
this->err.clear();
173+
171174
if (!this->InternalLoadPlugin())
172175
return;
173176

src/components/Plugins/inc/plugins/CPPPlugin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class CPPPlugin : public Plugin
3434
if (!this->m_hModule)
3535
{
3636
PRINTF("LoadPlugin", "Failed to load module: %s\n", std::string(dlerror()).c_str());
37+
this->err = std::string(dlerror()).c_str();
3738
return false;
3839
}
3940
#endif

src/components/Plugins/inc/plugins/LuaPlugin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class LuaPlugin : public Plugin
6464
if (!this->luaState->DoFile(file.c_str(), &errstr, nullptr))
6565
{
6666
PRINTF("LoadPlugin", "Failed to load plugin file '%s'\nError: %s\n", file.c_str(), errstr.c_str());
67+
this->err = errstr;
6768
this->StopPlugin();
6869
return false;
6970
}

src/components/Plugins/src/PluginsComponent.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void PluginsComponent::LoadComponent()
2525
std::vector<std::string> directories = Files::FetchDirectories("addons/swiftly/plugins");
2626
for (std::string directory : directories)
2727
{
28-
if (directory == "disabled")
28+
if (directory.find("disabled") != std::string::npos)
2929
continue;
3030

3131
directory = replace(directory, "addons/swiftly/plugins", "");

0 commit comments

Comments
 (0)