Don't truncate plugin installation errors

cshd
Dragory 2020-11-22 12:56:41 +02:00
parent 3f3de28091
commit 4a548dc261
No known key found for this signature in database
GPG Key ID: 5F387BA66DF8AAC1
3 changed files with 13 additions and 3 deletions

View File

@ -0,0 +1,5 @@
class PluginInstallationError extends Error {}
module.exports = {
PluginInstallationError,
};

View File

@ -17,6 +17,7 @@ try {
} }
const { BotError } = require("./BotError"); const { BotError } = require("./BotError");
const { PluginInstallationError } = require("./PluginInstallationError");
// Error handling // Error handling
// Force crash on unhandled rejections and uncaught exceptions. // Force crash on unhandled rejections and uncaught exceptions.
@ -46,6 +47,9 @@ function errorHandler(err) {
fullMessage += "4. Turn on 'Server Members Intent'" fullMessage += "4. Turn on 'Server Members Intent'"
console.error(fullMessage); console.error(fullMessage);
} else if (err instanceof PluginInstallationError) {
// Don't truncate PluginInstallationErrors as they can get lengthy
console.error(err);
} else { } else {
// Truncate long stack traces for other errors // Truncate long stack traces for other errors
const stack = err.stack || ""; const stack = err.stack || "";

View File

@ -9,6 +9,7 @@ const pacote = require("pacote");
const path = require("path"); const path = require("path");
const threads = require("./data/threads"); const threads = require("./data/threads");
const displayRoles = require("./data/displayRoles"); const displayRoles = require("./data/displayRoles");
const { PluginInstallationError } = require("./PluginInstallationError");
const pluginSources = { const pluginSources = {
npm: { npm: {
@ -40,7 +41,7 @@ const pluginSources = {
npmProcess.stderr.on("data", data => { stderr += String(data) }); npmProcess.stderr.on("data", data => { stderr += String(data) });
npmProcess.on("close", code => { npmProcess.on("close", code => {
if (code !== 0) { if (code !== 0) {
return reject(new Error(stderr)); return reject(new PluginInstallationError(stderr));
} }
return resolve(); return resolve();
@ -53,7 +54,7 @@ const pluginSources = {
const packageName = manifest.name; const packageName = manifest.name;
const pluginFn = require(packageName); const pluginFn = require(packageName);
if (typeof pluginFn !== "function") { 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); return pluginFn(pluginApi);
@ -66,7 +67,7 @@ const pluginSources = {
const requirePath = path.join(__dirname, "..", plugin); const requirePath = path.join(__dirname, "..", plugin);
const pluginFn = require(requirePath); const pluginFn = require(requirePath);
if (typeof pluginFn !== "function") { 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); return pluginFn(pluginApi);
}, },