diff --git a/firestore-send-email/functions/src/validation.ts b/firestore-send-email/functions/src/validation.ts index 98f4e4ca7..cbc6441dd 100644 --- a/firestore-send-email/functions/src/validation.ts +++ b/firestore-send-email/functions/src/validation.ts @@ -53,7 +53,10 @@ export const attachmentSchema = z }); export const attachmentsSchema = z - .array(attachmentSchema) + .array(attachmentSchema, { + invalid_type_error: + "Field 'attachments' must be an array. If you have a single attachment object, wrap it in an array (e.g., [{ filename: '...', path: '...' }])", + }) .optional() .transform((attachments) => attachments @@ -184,12 +187,21 @@ function formatZodError( const path = issue.path.length > 0 ? issue.path.join(".") : context; switch (issue.code) { case "invalid_type": + if (issue.received === "undefined") { + const expected = issue.expected === "object" ? "map" : issue.expected; + const article = ["a", "e", "i", "o", "u"].includes(expected[0]) + ? "an" + : "a"; + return `Field '${path}' must be ${article} ${expected}`; + } + if (issue.expected === "string") { return `Field '${path}' must be a string`; } if (issue.expected === "array") { return `Field '${path}' must be an array`; } + if (issue.expected === "object") { return `Field '${path}' must be a map`; }