diff --git a/backend/src/plugins/Tags/commands/TagEvalCmd.ts b/backend/src/plugins/Tags/commands/TagEvalCmd.ts index 55659d30..27cbe4f3 100644 --- a/backend/src/plugins/Tags/commands/TagEvalCmd.ts +++ b/backend/src/plugins/Tags/commands/TagEvalCmd.ts @@ -5,6 +5,7 @@ import { TemplateParseError } from "../../../templateFormatter"; import { memberToTemplateSafeMember, userToTemplateSafeUser } from "../../../utils/templateSafeObjects"; import { tagsCmd } from "../types"; import { renderTagBody } from "../util/renderTagBody"; +import { logger } from "../../../logger"; export const TagEvalCmd = tagsCmd({ trigger: "tag eval", @@ -34,12 +35,17 @@ export const TagEvalCmd = tagsCmd({ msg.channel.send(rendered); } catch (e) { - if (e instanceof TemplateParseError) { - sendErrorMessage(pluginData, msg.channel, `Failed to render tag: ${e.message}`); - return; + const errorMessage = e instanceof TemplateParseError + ? e.message + : "Internal error"; + + sendErrorMessage(pluginData, msg.channel, `Failed to render tag: ${errorMessage}`); + + if (! (e instanceof TemplateParseError)) { + logger.warn(`Internal error evaluating tag in ${pluginData.guild.id}: ${e}`); } - throw e; + return; } }, }); diff --git a/backend/src/plugins/Tags/util/renderTagFromString.ts b/backend/src/plugins/Tags/util/renderTagFromString.ts index 55e699fa..f1265858 100644 --- a/backend/src/plugins/Tags/util/renderTagFromString.ts +++ b/backend/src/plugins/Tags/util/renderTagFromString.ts @@ -7,6 +7,7 @@ import { memberToTemplateSafeMember, userToTemplateSafeUser } from "../../../uti import { LogsPlugin } from "../../Logs/LogsPlugin"; import { TTag, TagsPluginType } from "../types"; import { renderTagBody } from "./renderTagBody"; +import { logger } from "../../../logger"; export async function renderTagFromString( pluginData: GuildPluginData, @@ -34,14 +35,18 @@ export async function renderTagFromString( return validateAndParseMessageContent(rendered); } catch (e) { - if (e instanceof TemplateParseError) { - const logs = pluginData.getPlugin(LogsPlugin); - logs.logBotAlert({ - body: `Failed to render tag \`${prefix}${tagName}\`: ${e.message}`, - }); - return null; + const logs = pluginData.getPlugin(LogsPlugin); + const errorMessage = e instanceof TemplateParseError + ? e.message + : "Internal error"; + logs.logBotAlert({ + body: `Failed to render tag \`${prefix}${tagName}\`: ${errorMessage}`, + }); + + if (! (e instanceof TemplateParseError)) { + logger.warn(`Internal error rendering tag ${tagName} in ${pluginData.guild.id}: ${e}`); } - throw e; + return null; } }