diff --git a/src/modules/plugin.ts b/src/modules/plugin.ts index 8ed955c..849ca88 100644 --- a/src/modules/plugin.ts +++ b/src/modules/plugin.ts @@ -147,22 +147,33 @@ export class PluginAPIManager { } let plugin: Plugin; + let pluginPath = paths.shift(); try { - plugin = require(paths.shift() as string) as Plugin; + plugin = require(pluginPath as string) as Plugin; } catch (e) { throw e; } log.debug("Loaded plugin %s", moduleName); - return this.loadPluginInstance(plugin); + const instance = await this.loadPluginInstance(plugin); + + if (!instance) { + throw new Error(`Corrupt plugin found at ${pluginPath}`); + } + + return instance as Plugin; } - public async loadPluginInstance(plugin: Plugin): Promise { + public async loadPluginInstance(plugin: Plugin): Promise { if ("default" in plugin) { plugin = plugin?.default as Plugin; } + if (!("name" in plugin)) { + return false; + } + plugin.name = sanitizeName(plugin.name); this.registeredPlugins.set(plugin.name, plugin);