aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-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
4 files changed, 47 insertions, 4 deletions
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;