3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-15 05:41:51 +00:00

feat: more robust tag error handling

This commit is contained in:
Dragory 2023-11-25 12:15:32 +02:00
parent 09b6d43a5c
commit c82e147ea1
No known key found for this signature in database
2 changed files with 22 additions and 11 deletions

View file

@ -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;
}
},
});

View file

@ -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<TagsPluginType>,
@ -34,14 +35,18 @@ export async function renderTagFromString(
return validateAndParseMessageContent(rendered);
} catch (e) {
if (e instanceof TemplateParseError) {
const logs = pluginData.getPlugin(LogsPlugin);
const errorMessage = e instanceof TemplateParseError
? e.message
: "Internal error";
logs.logBotAlert({
body: `Failed to render tag \`${prefix}${tagName}\`: ${e.message}`,
body: `Failed to render tag \`${prefix}${tagName}\`: ${errorMessage}`,
});
return null;
if (! (e instanceof TemplateParseError)) {
logger.warn(`Internal error rendering tag ${tagName} in ${pluginData.guild.id}: ${e}`);
}
throw e;
return null;
}
}