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 { memberToTemplateSafeMember, userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
|
||||||
import { tagsCmd } from "../types";
|
import { tagsCmd } from "../types";
|
||||||
import { renderTagBody } from "../util/renderTagBody";
|
import { renderTagBody } from "../util/renderTagBody";
|
||||||
|
import { logger } from "../../../logger";
|
||||||
|
|
||||||
export const TagEvalCmd = tagsCmd({
|
export const TagEvalCmd = tagsCmd({
|
||||||
trigger: "tag eval",
|
trigger: "tag eval",
|
||||||
|
@ -34,12 +35,17 @@ export const TagEvalCmd = tagsCmd({
|
||||||
|
|
||||||
msg.channel.send(rendered);
|
msg.channel.send(rendered);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof TemplateParseError) {
|
const errorMessage = e instanceof TemplateParseError
|
||||||
sendErrorMessage(pluginData, msg.channel, `Failed to render tag: ${e.message}`);
|
? e.message
|
||||||
return;
|
: "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 { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||||
import { TTag, TagsPluginType } from "../types";
|
import { TTag, TagsPluginType } from "../types";
|
||||||
import { renderTagBody } from "./renderTagBody";
|
import { renderTagBody } from "./renderTagBody";
|
||||||
|
import { logger } from "../../../logger";
|
||||||
|
|
||||||
export async function renderTagFromString(
|
export async function renderTagFromString(
|
||||||
pluginData: GuildPluginData<TagsPluginType>,
|
pluginData: GuildPluginData<TagsPluginType>,
|
||||||
|
@ -34,14 +35,18 @@ export async function renderTagFromString(
|
||||||
|
|
||||||
return validateAndParseMessageContent(rendered);
|
return validateAndParseMessageContent(rendered);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof TemplateParseError) {
|
const logs = pluginData.getPlugin(LogsPlugin);
|
||||||
const logs = pluginData.getPlugin(LogsPlugin);
|
const errorMessage = e instanceof TemplateParseError
|
||||||
logs.logBotAlert({
|
? e.message
|
||||||
body: `Failed to render tag \`${prefix}${tagName}\`: ${e.message}`,
|
: "Internal error";
|
||||||
});
|
logs.logBotAlert({
|
||||||
return null;
|
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