{"record":{"id":"6bc6302a32376b97","repo":"can1357/oh-my-pi","slug":"enum-requires-at-least-one-value","errorCode":null,"errorMessage":"enum requires at least one value","messagePattern":"enum requires at least one value","errorType":"exception","errorClass":"OmpTypeError","httpStatus":null,"severity":"error","filePath":"packages/omptype/src/zod.ts","lineNumber":291,"sourceCode":"\t\t\tprop.def = member.defaultValue;\n\t\t\tprop.defFactory = typeof member.defaultValue === \"function\";\n\t\t}\n\t\tprops.push(prop);\n\t}\n\treturn decorateUnknown(schemaFromIR<unknown>({ k: \"object\", props, extras: \"delete\" })) as unknown as ZodLikeSchema<\n\t\tObjectOutput<S>\n\t>;\n}\n\nexport const string = (): ZodLikeSchema<string> => decorate(schemaFromIR(type.string.ir));\nexport const number = (): ZodLikeSchema<number> => decorate(schemaFromIR(type.number.ir));\nexport const boolean = (): ZodLikeSchema<boolean> => decorate(schemaFromIR(type.boolean.ir));\nexport const literal = <const Value>(value: Value): ZodLikeSchema<Value> =>\n\tdecorate(schemaFromIR<Value>(type.enumerated(value).ir));\nconst enumSchema = <const Values extends readonly [string, ...string[]]>(\n\tvalues: Values,\n): ZodLikeSchema<Values[number]> => {\n\tif (values.length === 0) throw new OmpTypeError(\"enum requires at least one value\");\n\treturn decorate(schemaFromIR<Values[number]>(type.enumerated(...values).ir));\n};\n\nexport { enumSchema as enum };\nexport const union = <\n\tconst Schemas extends readonly [ZodLikeSchema<unknown>, ZodLikeSchema<unknown>, ...ZodLikeSchema<unknown>[]],\n>(\n\tschemas: Schemas,\n): ZodLikeSchema<UnionOutput<Schemas>> =>\n\tdecorate(schemaFromIR({ k: \"union\", members: schemas.map(schema => embed(schema)) }));\nexport const array = <Element>(element: ZodLikeSchema<Element>): ZodLikeSchema<Element[]> =>\n\tdecorate(schemaFromIR({ k: \"array\", el: embed(element) }));\nexport const object = <const S extends Shape>(shape: S): ZodLikeSchema<Simplify<ObjectOutput<S>>> =>\n\tobjectSchema(shape);\nexport const record = <Key extends string, Value>(\n\tkeySchema: ZodLikeSchema<Key>,\n\tvalueSchema: ZodLikeSchema<Value>,\n): ZodLikeSchema<Record<string, Value>> => {","sourceCodeStart":273,"sourceCodeEnd":309,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/omptype/src/zod.ts#L273-L309","documentation":"`omptype.enum()` requires at least one value to enumerate over; an empty value set has no members and cannot validate anything, so it throws an OmpTypeError. Thrown from `enumSchema` at packages/omptype/src/zod.ts:291 when the values array has length 0.","triggerScenarios":"`omptype.enum([])`; or `omptype.enum(someArray)` where someArray is an empty array at runtime (values filtered, config missing) even though the TypeScript signature `readonly [string, ...string[]]` demands a non-empty tuple.","commonSituations":"Enum values loaded from config/env/DB that end up empty; building enum schemas from dynamically collected keys where the collection is empty; casting `[] as any` to satisfy the type signature.","solutions":["Pass at least one string literal: omptype.enum([\"a\", \"b\"])","Check the source array for emptiness before constructing the schema and provide a default","Avoid unsafe casts that silence the non-empty tuple requirement; validate the runtime array first"],"exampleFix":"// before\nconst statuses = config.statuses ?? [];\nconst schema = omptype.enum(statuses); // throws when empty\n// after\nconst statuses = config.statuses?.length ? config.statuses : [\"active\"];\nconst schema = omptype.enum(statuses);","handlingStrategy":"validation","validationCode":"function assertNonEmptyEnum(values: readonly string[]): void {\n  if (values.length === 0) throw new Error(\"enum needs at least one value; check the source config/collection\");\n}\nassertNonEmptyEnum(statuses); // before omptype.enum(statuses)","typeGuard":"function isNonEmptyStringTuple(values: readonly string[]): values is readonly [string, ...string[]] {\n  return values.length > 0;\n}","tryCatchPattern":"try {\n  schema = omptype.enum(values);\n} catch (err) {\n  if (err instanceof OmpTypeError && err.message.includes(\"at least one value\")) {\n    schema = omptype.enum([fallbackValue]);\n  } else throw err;\n}","preventionTips":["Never construct enum schemas from config/env-derived arrays without an emptiness check","Prefer literal arrays omptype.enum([\"a\",\"b\"]) so TypeScript's non-empty tuple type catches it at compile time","Avoid `as any`/`as never` casts that silence the non-empty tuple requirement"],"tags":["schema-builder","enum","empty-input"],"backgroundTag":"empty-enum-values","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}