diff --git a/src/PluginInstallationError.js b/src/PluginInstallationError.js new file mode 100644 index 0000000..05bad2c --- /dev/null +++ b/src/PluginInstallationError.js @@ -0,0 +1,5 @@ +class PluginInstallationError extends Error {} + +module.exports = { + PluginInstallationError, +}; diff --git a/src/index.js b/src/index.js index bc67f95..98eadb4 100644 --- a/src/index.js +++ b/src/index.js @@ -17,6 +17,7 @@ try { } const { BotError } = require("./BotError"); +const { PluginInstallationError } = require("./PluginInstallationError"); // Error handling // Force crash on unhandled rejections and uncaught exceptions. @@ -46,6 +47,9 @@ function errorHandler(err) { fullMessage += "4. Turn on 'Server Members Intent'" console.error(fullMessage); + } else if (err instanceof PluginInstallationError) { + // Don't truncate PluginInstallationErrors as they can get lengthy + console.error(err); } else { // Truncate long stack traces for other errors const stack = err.stack || ""; diff --git a/src/plugins.js b/src/plugins.js index aca0a98..15d525a 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -9,6 +9,7 @@ const pacote = require("pacote"); const path = require("path"); const threads = require("./data/threads"); const displayRoles = require("./data/displayRoles"); +const { PluginInstallationError } = require("./PluginInstallationError"); const pluginSources = { npm: { @@ -40,7 +41,7 @@ const pluginSources = { npmProcess.stderr.on("data", data => { stderr += String(data) }); npmProcess.on("close", code => { if (code !== 0) { - return reject(new Error(stderr)); + return reject(new PluginInstallationError(stderr)); } return resolve(); @@ -53,7 +54,7 @@ const pluginSources = { const packageName = manifest.name; const pluginFn = require(packageName); if (typeof pluginFn !== "function") { - throw new Error(`Plugin '${plugin}' is not a valid plugin`); + throw new PluginInstallationError(`Plugin '${plugin}' is not a valid plugin`); } return pluginFn(pluginApi); @@ -66,7 +67,7 @@ const pluginSources = { const requirePath = path.join(__dirname, "..", plugin); const pluginFn = require(requirePath); if (typeof pluginFn !== "function") { - throw new Error(`Plugin '${plugin}' is not a valid plugin`); + throw new PluginInstallationError(`Plugin '${plugin}' is not a valid plugin`); } return pluginFn(pluginApi); },