Skip to content

Commit

Permalink
Better display for thread management script loading errors
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Shadowfiend committed Jan 4, 2024
1 parent 5f71ed6 commit 15d853b
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions discord-scripts/thread-management.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
)
}
})
Expand Down

0 comments on commit 15d853b

Please sign in to comment.