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 { 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 || "";

View File

@ -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);
},