{"record":{"id":"13b31cd4fc8aca58","repo":"FlowiseAI/Flowise","slug":"enum-requires-array-of-values","errorCode":null,"errorMessage":"enum requires array of values","messagePattern":"enum requires array of values","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/components/src/secureZodParser.ts","lineNumber":616,"sourceCode":"        switch (typeInfo.base) {\n            case 'string':\n                zodType = z.string()\n                break\n            case 'number':\n                zodType = z.number()\n                break\n            case 'boolean':\n                zodType = z.boolean()\n                break\n            case 'date':\n                zodType = z.date()\n                break\n            case 'enum':\n                if (typeInfo.baseArgs && typeInfo.baseArgs[0] && Array.isArray(typeInfo.baseArgs[0])) {\n                    const enumValues = typeInfo.baseArgs[0] as [string, ...string[]]\n                    zodType = z.enum(enumValues)\n                } else {\n                    throw new Error('enum requires array of values')\n                }\n                break\n            default:\n                throw new Error(`Unsupported base type: ${typeInfo.base}`)\n        }\n\n        // Apply modifiers\n        zodType = this.applyModifiers(zodType, typeInfo.modifiers || [])\n\n        return zodType\n    }\n\n    private static applyModifiers(zodType: z.ZodTypeAny, modifiers: any[]): z.ZodTypeAny {\n        for (const modifier of modifiers) {\n            switch (modifier.name) {\n                case 'int':\n                    if (zodType._def?.typeName === 'ZodNumber') {\n                        zodType = (zodType as z.ZodNumber).int()","sourceCodeStart":598,"sourceCodeEnd":634,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/src/secureZodParser.ts#L598-L634","documentation":"Thrown in buildZodSchema's `enum` case when the parsed type info does not carry an array as its first base argument. `z.enum(...)` in Zod requires a non-empty tuple of string literals, so the secure parser refuses to construct it without one.","triggerScenarios":"A schema string like `z.enum()` with no values, or `z.enum('a')`/`z.enum(\"a\",\"b\")` where the argument parser failed to surface the values as an array in typeInfo.baseArgs[0]. The guard is `typeInfo.baseArgs && typeInfo.baseArgs[0] && Array.isArray(typeInfo.baseArgs[0])` at secureZodParser.ts:612.","commonSituations":"Forgetting the array brackets in an enum schema; a malformed schema string where the argument extractor did not recognize the literal array syntax.","solutions":["Write the enum values as an array literal, e.g. `z.enum([\"red\",\"green\",\"blue\"])`.","Ensure at least one value is present — an empty array is not a valid Zod enum.","If the schema is generated, confirm the generator emits the array form expected by the parser."],"exampleFix":"// before\nconst schema = \"z.object({ color: z.enum() })\"\n// after\nconst schema = \"z.object({ color: z.enum([\\\"red\\\",\\\"green\\\",\\\"blue\\\"]) })\"","handlingStrategy":"validation","validationCode":"function validateEnumSchema(schemaStr: string): string[] {\n  const issues: string[] = []\n  for (const m of schemaStr.matchAll(/z\\.enum\\s*\\(([^)]*)\\)/g)) {\n    const args = m[1].trim()\n    if (!args.startsWith('[') || !/\\[[^\\]]*\\]/.test(args)) issues.push('enum must be given an array literal')\n  }\n  return issues\n}","typeGuard":"function hasEnumValues(baseArgs: unknown): baseArgs is [string, ...string[]] {\n  return Array.isArray(baseArgs) && Array.isArray(baseArgs[0]) && (baseArgs[0] as unknown[]).length > 0 &&\n    (baseArgs[0] as unknown[]).every(v => typeof v === 'string')\n}","tryCatchPattern":"try {\n  const schema = SecureZodSchemaParser.parseZodSchema(schemaStr)\n} catch (e) {\n  if (/enum requires array of values/.test(e.message)) {\n    // rewrite enum as z.enum([\"a\",\"b\"]) and retry\n  }\n  throw e\n}","preventionTips":["Always write enum values as an array literal: z.enum([\"a\",\"b\"]).","Never emit an empty enum.","If generating schemas, unit-test the enum emission."],"tags":["zod","enum","validation","schema"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}