mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-14 21:31:50 +00:00
feat: more robust tag error handling
This commit is contained in:
parent
09b6d43a5c
commit
c82e147ea1
2 changed files with 22 additions and 11 deletions
|
@ -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;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue