3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-06-17 03:25:01 +00:00

feat: handle template errors

Fixes ZDEV-20
This commit is contained in:
Dragory 2024-01-27 16:01:48 +02:00
parent 2ce5082018
commit ffa9eeb3f5
No known key found for this signature in database
14 changed files with 231 additions and 94 deletions

View file

@ -4,6 +4,7 @@ import { canActOn } from "../../../pluginUtils";
import { renderTemplate, TemplateSafeValueContainer } from "../../../templateFormatter";
import { resolveMember, zSnowflake } from "../../../utils";
import { ActionError } from "../ActionError";
import { catchTemplateError } from "../catchTemplateError";
import { CustomEventsPluginType, TCustomEvent } from "../types";
export const zAddRoleAction = z.strictObject({
@ -20,7 +21,10 @@ export async function addRoleAction(
event: TCustomEvent,
eventData: any,
) {
const targetId = await renderTemplate(action.target, values, false);
const targetId = await catchTemplateError(
() => renderTemplate(action.target, values, false),
"Invalid target format",
);
const target = await resolveMember(pluginData.client, pluginData.guild, targetId);
if (!target) throw new ActionError(`Unknown target member: ${targetId}`);