can1357/oh-my-pi · error · OmpTypeError
enum requires at least one value
Error message
enum requires at least one value
What it means
`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.
Source
Thrown at packages/omptype/src/zod.ts:291
prop.def = member.defaultValue;
prop.defFactory = typeof member.defaultValue === "function";
}
props.push(prop);
}
return decorateUnknown(schemaFromIR<unknown>({ k: "object", props, extras: "delete" })) as unknown as ZodLikeSchema<
ObjectOutput<S>
>;
}
export const string = (): ZodLikeSchema<string> => decorate(schemaFromIR(type.string.ir));
export const number = (): ZodLikeSchema<number> => decorate(schemaFromIR(type.number.ir));
export const boolean = (): ZodLikeSchema<boolean> => decorate(schemaFromIR(type.boolean.ir));
export const literal = <const Value>(value: Value): ZodLikeSchema<Value> =>
decorate(schemaFromIR<Value>(type.enumerated(value).ir));
const enumSchema = <const Values extends readonly [string, ...string[]]>(
values: Values,
): ZodLikeSchema<Values[number]> => {
if (values.length === 0) throw new OmpTypeError("enum requires at least one value");
return decorate(schemaFromIR<Values[number]>(type.enumerated(...values).ir));
};
export { enumSchema as enum };
export const union = <
const Schemas extends readonly [ZodLikeSchema<unknown>, ZodLikeSchema<unknown>, ...ZodLikeSchema<unknown>[]],
>(
schemas: Schemas,
): ZodLikeSchema<UnionOutput<Schemas>> =>
decorate(schemaFromIR({ k: "union", members: schemas.map(schema => embed(schema)) }));
export const array = <Element>(element: ZodLikeSchema<Element>): ZodLikeSchema<Element[]> =>
decorate(schemaFromIR({ k: "array", el: embed(element) }));
export const object = <const S extends Shape>(shape: S): ZodLikeSchema<Simplify<ObjectOutput<S>>> =>
objectSchema(shape);
export const record = <Key extends string, Value>(
keySchema: ZodLikeSchema<Key>,
valueSchema: ZodLikeSchema<Value>,
): ZodLikeSchema<Record<string, Value>> => {View on GitHub (pinned to 9690622007)
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
Example fix
// before const statuses = config.statuses ?? []; const schema = omptype.enum(statuses); // throws when empty // after const statuses = config.statuses?.length ? config.statuses : ["active"]; const schema = omptype.enum(statuses);
Defensive patterns
Strategy: validation
Validate before calling
function assertNonEmptyEnum(values: readonly string[]): void {
if (values.length === 0) throw new Error("enum needs at least one value; check the source config/collection");
}
assertNonEmptyEnum(statuses); // before omptype.enum(statuses) Type guard
function isNonEmptyStringTuple(values: readonly string[]): values is readonly [string, ...string[]] {
return values.length > 0;
} Try / catch
try {
schema = omptype.enum(values);
} catch (err) {
if (err instanceof OmpTypeError && err.message.includes("at least one value")) {
schema = omptype.enum([fallbackValue]);
} else throw err;
} Prevention
- 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
When it happens
Trigger: `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.
Common situations: 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.
Related errors
- Unsupported language '{value}'. Supported: {}
- Expected int32, got ${typeof value}
- Managed skill "${name}" needs a non-empty description.
- Managed skill "${name}" needs a non-empty body.
- litterbox option ttl must be one of 1h, 12h, 24h, or 72h
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/6bc6302a32376b97.
Report an issue: GitHub.