From 15d853b8f620d75a2f19072991285e5c998b9a56 Mon Sep 17 00:00:00 2001 From: Antonio Salazar Cardozo Date: Thu, 4 Jan 2024 07:06:24 -0500 Subject: [PATCH] Better display for thread management script loading errors Sometimes errors will JSON-serialize, but sometimes they won't; in the latter case, we want to try to use the error's built-in stringification in case it works better. --- discord-scripts/thread-management.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/discord-scripts/thread-management.ts b/discord-scripts/thread-management.ts index 9520bac6..3f36b433 100644 --- a/discord-scripts/thread-management.ts +++ b/discord-scripts/thread-management.ts @@ -52,12 +52,13 @@ export default function manageThreads(discordClient: Client, robot: Robot) { // eslint-disable-next-line @typescript-eslint/no-explicit-any "stack" in (error as any) ? `\n${(error as any).stack}` : "" + const errorJson = JSON.stringify(error, null, 2) + + const errorDescription = + errorJson.trim().length > 0 ? errorJson : String(error) + robot.logger.error( - `Failed to load Discord script ${file}: ${JSON.stringify( - error, - null, - 2, - )}${stackString}`, + `Failed to load Discord script ${file}: ${errorDescription}${stackString}`, ) } })