Skip to content

Commit 6968033

Browse files
committed
Prevent crash when trying to list an invalid plugin
There was no error catching before when listing plugins, which led to a crash of the bot every time someone tries to list all plugins in the plugin directory if it contains a plugin that is in some shape or form not loadable. A try/catch prevents this from happening and tells the user that the plugin has errored out.
1 parent 5b67089 commit 6968033

1 file changed

Lines changed: 27 additions & 16 deletions

File tree

app.js

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -568,23 +568,34 @@ function plugin_cmd(args) {
568568
var plugin_info; var plugin_state; var plugin;
569569
var list = plugin_loader.listPlugins();
570570
for (var plugin_index in list) {
571-
plugin = list[plugin_index];
572-
plugin_info = plugin_loader.getPluginInfo(plugin);
573-
if (plugin_loader.isPluginRunning(plugin)) {
574-
plugin_state = "Running";
575-
} else if (plugin_loader.isPluginLoaded(plugin)) {
576-
plugin_state = "Stopped";
577-
} else {
578-
plugin_state = "Unloaded"
571+
try {
572+
plugin = list[plugin_index];
573+
plugin_info = plugin_loader.getPluginInfo(plugin);
574+
if (plugin_loader.isPluginRunning(plugin)) {
575+
plugin_state = "Running";
576+
} else if (plugin_loader.isPluginLoaded(plugin)) {
577+
plugin_state = "Stopped";
578+
} else {
579+
plugin_state = "Unloaded"
580+
}
581+
data.push({
582+
plugin_name: plugin_info.Name,
583+
plugin_version: plugin_info.Version,
584+
plugin_author: plugin_info.Author,
585+
plugin_description: plugin_info.Description,
586+
plugin_state: plugin_state,
587+
plugin_file: plugin.replace(/\.dbot\.js/, ""),
588+
});
589+
} catch (ex) {
590+
data.push({
591+
plugin_name: "ERROR",
592+
plugin_version: "ERROR",
593+
plugin_author: "ERROR",
594+
plugin_description: ex,
595+
plugin_state: "errored",
596+
plugin_file: plugin.replace(/\.dbot\.js/, ""),
597+
});
579598
}
580-
data.push({
581-
plugin_name: plugin_info.Name,
582-
plugin_version: plugin_info.Version,
583-
plugin_author: plugin_info.Author,
584-
plugin_description: plugin_info.Description,
585-
plugin_state: plugin_state,
586-
plugin_file: plugin.replace(/\.pbot\.js/, ""),
587-
});
588599
data.push(column_divider);
589600
}
590601
console.log(

0 commit comments

Comments
 (0)