aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-05-27 22:39:07 -0400
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-05-27 22:39:07 -0400
commit94c20f17f1a87e594fc07a75eb6026891086c67c (patch)
treef32942ce07630352afbf4d7be2b718fc9724502c /src
parentf718df9321f2ff28a5a1f20d53e474fbf5998d6e (diff)
downloadtanzanite-94c20f17f1a87e594fc07a75eb6026891086c67c.tar.gz
tanzanite-94c20f17f1a87e594fc07a75eb6026891086c67c.tar.bz2
tanzanite-94c20f17f1a87e594fc07a75eb6026891086c67c.zip
fix: use util#formatError
Diffstat (limited to 'src')
-rw-r--r--src/commands/admin/channelPermissions.ts2
-rw-r--r--src/commands/dev/reload.ts2
-rw-r--r--src/commands/dev/sh.ts2
-rw-r--r--src/commands/utilities/decode.ts2
-rw-r--r--src/lib/common/AutoMod.ts2
-rw-r--r--src/lib/extensions/discord-akairo/BushClient.ts6
-rw-r--r--src/lib/extensions/discord-akairo/BushClientUtil.ts41
-rw-r--r--src/lib/extensions/discord.js/BushGuildMember.ts2
-rw-r--r--src/listeners/commands/commandError.ts4
-rw-r--r--src/listeners/contextCommands/contextCommandError.ts2
-rw-r--r--src/listeners/other/promiseRejection.ts6
-rw-r--r--src/listeners/other/uncaughtException.ts6
-rw-r--r--src/listeners/other/warning.ts2
13 files changed, 57 insertions, 22 deletions
diff --git a/src/commands/admin/channelPermissions.ts b/src/commands/admin/channelPermissions.ts
index dac7117..15f1260 100644
--- a/src/commands/admin/channelPermissions.ts
+++ b/src/commands/admin/channelPermissions.ts
@@ -83,7 +83,7 @@ export default class ChannelPermissionsCommand extends BushCommand {
{ reason: 'Changing overwrites for mass channel perms command' }
);
} catch (e) {
- void client.console.error('channelPermissions', e.stack);
+ void client.console.error('channelPermissions', util.formatError(e));
failedChannels.push(channel);
}
}
diff --git a/src/commands/dev/reload.ts b/src/commands/dev/reload.ts
index d874c83..17802b0 100644
--- a/src/commands/dev/reload.ts
+++ b/src/commands/dev/reload.ts
@@ -47,7 +47,7 @@ export default class ReloadCommand extends BushCommand {
} catch (e) {
if (output!) void client.logger.error('reloadCommand', output);
return message.util.send(
- `An error occurred while reloading:\n${await util.codeblock(e?.stack || e, 2048 - 34, 'js', true)}`
+ `An error occurred while reloading:\n${await util.codeblock(util.formatError(e), 2048 - 34, 'js', true)}`
);
}
}
diff --git a/src/commands/dev/sh.ts b/src/commands/dev/sh.ts
index be6a015..e071e73 100644
--- a/src/commands/dev/sh.ts
+++ b/src/commands/dev/sh.ts
@@ -82,7 +82,7 @@ export default class ShCommand extends BushCommand {
.setColor(util.colors.error)
.spliceFields(1, 1);
- embed.addFields([{ name: '📤 Output', value: await util.codeblock(e?.stack, 1024, 'js', true) }]);
+ embed.addFields([{ name: '📤 Output', value: await util.codeblock(util.formatError(e), 1024, 'js', true) }]);
}
await message.util.edit({ embeds: [embed] });
}
diff --git a/src/commands/utilities/decode.ts b/src/commands/utilities/decode.ts
index 729cf35..7cb0e83 100644
--- a/src/commands/utilities/decode.ts
+++ b/src/commands/utilities/decode.ts
@@ -65,7 +65,7 @@ export default class DecodeCommand extends BushCommand {
decodedEmbed.setColor(util.colors.error).addFields([
{
name: `📤 Error ${encodeOrDecode.slice(1)}ing`,
- value: await util.inspectCleanRedactCodeblock(error?.stack ?? error)
+ value: await util.inspectCleanRedactCodeblock(util.formatError(error))
}
]);
}
diff --git a/src/lib/common/AutoMod.ts b/src/lib/common/AutoMod.ts
index b08fc40..f30eab7 100644
--- a/src/lib/common/AutoMod.ts
+++ b/src/lib/common/AutoMod.ts
@@ -300,7 +300,7 @@ export class AutoMod {
{
title: 'AutoMod Error',
description: `Unable to delete triggered message.`,
- fields: [{ name: 'Error', value: await util.codeblock(`${e.stack ?? e}`, 1024, 'js', true) }],
+ fields: [{ name: 'Error', value: await util.codeblock(`${util.formatError(e)}`, 1024, 'js', true) }],
color: util.colors.error
}
]
diff --git a/src/lib/extensions/discord-akairo/BushClient.ts b/src/lib/extensions/discord-akairo/BushClient.ts
index 847631c..ac4de5f 100644
--- a/src/lib/extensions/discord-akairo/BushClient.ts
+++ b/src/lib/extensions/discord-akairo/BushClient.ts
@@ -431,7 +431,11 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re
void this.logger.success('startup', `Successfully loaded <<${handlerName}>>.`, false);
})
.catch((e) => {
- void this.logger.error('startup', `Unable to load loader <<${handlerName}>> with error:\n${e?.stack || e}`, false);
+ void this.logger.error(
+ 'startup',
+ `Unable to load loader <<${handlerName}>> with error:\n${util.formatError(e)}`,
+ false
+ );
if (process.argv.includes('dry')) process.exit(1);
})
);
diff --git a/src/lib/extensions/discord-akairo/BushClientUtil.ts b/src/lib/extensions/discord-akairo/BushClientUtil.ts
index 7629c38..c0df724 100644
--- a/src/lib/extensions/discord-akairo/BushClientUtil.ts
+++ b/src/lib/extensions/discord-akairo/BushClientUtil.ts
@@ -683,7 +683,7 @@ export class BushClientUtil extends ClientUtil {
* @param error
*/
public async handleError(context: string, error: Error) {
- await client.console.error(_.camelCase(context), `An error occurred:\n${error?.stack ?? (error as any)}`, false);
+ await client.console.error(_.camelCase(context), `An error occurred:\n${util.formatError(error)}`, false);
await client.console.channelError({
embeds: [await CommandErrorListener.generateErrorEmbed({ type: 'unhandledRejection', error: error, context })]
});
@@ -777,6 +777,27 @@ export class BushClientUtil extends ClientUtil {
}
/**
+ * List the symbols of an object.
+ * @param obj The object to get the symbols of.
+ * @returns An array of the symbols of the object.
+ */
+ public getSymbols(obj: Record<string, any>): symbol[] {
+ let symbols: symbol[] = [];
+ let obj_: Record<string, any> = new Object(obj);
+
+ do {
+ const l = Object.getOwnPropertySymbols(obj_).sort();
+
+ symbols = [...symbols, ...l];
+ } while (
+ (obj_ = Object.getPrototypeOf(obj_)) && // walk-up the prototype chain
+ Object.getPrototypeOf(obj_) // not the the Object prototype methods (hasOwnProperty, etc...)
+ );
+
+ return symbols;
+ }
+
+ /**
* Uploads an image to imgur.
* @param image The image to upload.
* @returns The url of the imgur.
@@ -1052,6 +1073,24 @@ export class BushClientUtil extends ClientUtil {
}
/**
+ * Formats an error into a string.
+ * @param error The error to format.
+ * @returns The formatted error.
+ */
+ public formatError(error: Error | any): string {
+ if (!error) return error;
+ if (typeof error !== 'object') return String.prototype.toString.call(error);
+ if (
+ this.getSymbols(error)
+ .map((s) => s.toString())
+ .includes('Symbol(util.inspect.custom)')
+ )
+ return error.inspect();
+
+ return error.stack;
+ }
+
+ /**
* A wrapper for the Argument class that adds custom typings.
*/
public get arg() {
diff --git a/src/lib/extensions/discord.js/BushGuildMember.ts b/src/lib/extensions/discord.js/BushGuildMember.ts
index 5e9e150..7cc89d2 100644
--- a/src/lib/extensions/discord.js/BushGuildMember.ts
+++ b/src/lib/extensions/discord.js/BushGuildMember.ts
@@ -373,7 +373,7 @@ export class BushGuildMember extends GuildMember {
const muteSuccess = await this.roles
.remove(muteRole, `[Unmute] ${moderator.tag} | ${options.reason ?? 'No reason provided.'}`)
.catch(async (e) => {
- await client.console.warn('muteRoleAddError', e?.stack || e);
+ await client.console.warn('muteRoleAddError', util.formatError(e));
return false;
});
if (!muteSuccess) return unmuteResponse.ACTION_ERROR;
diff --git a/src/listeners/commands/commandError.ts b/src/listeners/commands/commandError.ts
index d590e06..895cff0 100644
--- a/src/listeners/commands/commandError.ts
+++ b/src/listeners/commands/commandError.ts
@@ -46,7 +46,7 @@ export default class CommandErrorListener extends BushListener {
`${isSlash ? 'slashC' : 'c'}ommandError`,
`an error occurred with the <<${command}>> ${isSlash ? 'slash ' : ''}command in <<${channel}>> triggered by <<${
message?.author?.tag
- }>>:\n${error?.stack ?? <any>error}`,
+ }>>:\n${util.formatError(error)})}`,
false
);
@@ -229,7 +229,7 @@ export default class CommandErrorListener extends BushListener {
}
public static async getErrorStack(error: Error | any): Promise<string> {
- return await util.inspectCleanRedactCodeblock(error?.stack ?? error, 'js');
+ return await util.inspectCleanRedactCodeblock(util.formatError(error), 'js');
}
}
diff --git a/src/listeners/contextCommands/contextCommandError.ts b/src/listeners/contextCommands/contextCommandError.ts
index 04a97ad..86cbac8 100644
--- a/src/listeners/contextCommands/contextCommandError.ts
+++ b/src/listeners/contextCommands/contextCommandError.ts
@@ -44,7 +44,7 @@ export default class ContextCommandErrorListener extends BushListener {
`contextCommandError`,
`an error occurred with the <<${command}>> context command in <<${channel}>> triggered by <<${
interaction?.user?.tag
- }>>:\n${error?.stack ?? <any>error}`,
+ }>>:\n${util.formatError(error)}`,
false
);
diff --git a/src/listeners/other/promiseRejection.ts b/src/listeners/other/promiseRejection.ts
index 69a62c7..270db46 100644
--- a/src/listeners/other/promiseRejection.ts
+++ b/src/listeners/other/promiseRejection.ts
@@ -21,11 +21,7 @@ export default class PromiseRejectionListener extends BushListener {
level: Severity.Error
});
- void client.console.error(
- 'promiseRejection',
- `An unhanded promise rejection occurred:\n${typeof error == 'object' ? error.stack : error}`,
- false
- );
+ void client.console.error('promiseRejection', `An unhanded promise rejection occurred:\n${util.formatError(error)}`, false);
if (!error.message.includes('reason: getaddrinfo ENOTFOUND canary.discord.com'))
void client.console.channelError({
embeds: [await CommandErrorListener.generateErrorEmbed({ type: 'unhandledRejection', error: error })]
diff --git a/src/listeners/other/uncaughtException.ts b/src/listeners/other/uncaughtException.ts
index b650620..b12f76d 100644
--- a/src/listeners/other/uncaughtException.ts
+++ b/src/listeners/other/uncaughtException.ts
@@ -20,11 +20,7 @@ export default class UncaughtExceptionListener extends BushListener {
level: Severity.Error
});
- void client.console.error(
- 'uncaughtException',
- `An uncaught exception occurred:\n${typeof error == 'object' ? error.stack : error}`,
- false
- );
+ void client.console.error('uncaughtException', `An uncaught exception occurred:\n${util.formatError(error)}`, false);
void client.console.channelError({
embeds: [await CommandErrorListener.generateErrorEmbed({ type: 'uncaughtException', error: error })]
});
diff --git a/src/listeners/other/warning.ts b/src/listeners/other/warning.ts
index 57f2a7d..2412221 100644
--- a/src/listeners/other/warning.ts
+++ b/src/listeners/other/warning.ts
@@ -17,7 +17,7 @@ export default class WarningListener extends BushListener {
level: Severity.Warning
});
- void client.console.warn('warning', `A warning occurred:\n${typeof error == 'object' ? error.stack : error}`, false);
+ void client.console.warn('warning', `A warning occurred:\n${util.formatError(error)}`, false);
void client.console.channelError({
embeds: [
(await CommandErrorListener.generateErrorEmbed({ type: 'unhandledRejection', error: error }))