{"id":"4c0425137fccab4f","repo":"drizzle-team/drizzle-orm","slug":"you-have-an-empty-array-for-name-enum-values-4c0425","errorCode":null,"errorMessage":"You have an empty array for \"${name}\" enum values","messagePattern":"You have an empty array for \"(.+?)\" enum values","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"drizzle-orm/src/singlestore-core/columns/enum.ts","lineNumber":80,"sourceCode":"\t\treturn `enum(${this.enumValues!.map((value) => `'${value}'`).join(',')})`;\n\t}\n}\n\nexport function singlestoreEnum<U extends string, T extends Readonly<[U, ...U[]]>>(\n\tvalues: T | Writable<T>,\n): SingleStoreEnumColumnBuilderInitial<'', Writable<T>>;\nexport function singlestoreEnum<TName extends string, U extends string, T extends Readonly<[U, ...U[]]>>(\n\tname: TName,\n\tvalues: T | Writable<T>,\n): SingleStoreEnumColumnBuilderInitial<TName, Writable<T>>;\nexport function singlestoreEnum(\n\ta?: string | readonly [string, ...string[]] | [string, ...string[]],\n\tb?: readonly [string, ...string[]] | [string, ...string[]],\n): any {\n\tconst { name, config: values } = getColumnNameAndConfig<readonly [string, ...string[]] | [string, ...string[]]>(a, b);\n\n\tif (values.length === 0) {\n\t\tthrow new Error(`You have an empty array for \"${name}\" enum values`);\n\t}\n\n\treturn new SingleStoreEnumColumnBuilder(name, values as any);\n}\n","sourceCodeStart":62,"sourceCodeEnd":85,"githubUrl":"https://github.com/drizzle-team/drizzle-orm/blob/b7862528fd8fc39bc2653a6c18dad7c1f4e68d10/drizzle-orm/src/singlestore-core/columns/enum.ts#L62-L85","documentation":"singlestoreEnum() throws when the values tuple passed to it is empty (values.length === 0). An enum column requires at least one value to generate valid DDL (ENUM('a',...)) and to satisfy its tuple type [string, ...string[]]; an empty array is treated as a schema definition error and rejected up front.","triggerScenarios":"Calling singlestoreEnum([]) or singlestoreEnum('name', []) or passing a variable that evaluates to an empty array, e.g. singlestoreEnum(roles) where roles is []. Also spreading a possibly-empty config-driven list: singlestoreEnum(...[...configValues]).","commonSituations":"Generating enum columns from a config/source list that is conditionally empty. Refactoring that leaves a placeholder singlestoreEnum([]) during scaffolding. Loading enum values from an external source that returns no entries.","solutions":["Provide at least one enum value: singlestoreEnum('role', ['admin']).","If values come from a dynamic source, guard with a non-empty check before defining the column and throw a clearer error or skip the table.","Fix the data source so it always returns the expected enum members."],"exampleFix":"// before (throws)\nconst roles: string[] = [];\nconst col = singlestoreEnum('role', roles as [string, ...string[]]);\n\n// after\nconst roles = ['admin', 'user'] as const;\nconst col = singlestoreEnum('role', roles);","handlingStrategy":"validation","validationCode":"function singlestoreEnumSafe(name: string, values: readonly string[]) {\n  if (!Array.isArray(values) || values.length === 0) {\n    throw new Error(`Enum \"${name}\" must have at least one value`);\n  }\n  return singlestoreEnum(name, values as [string, ...string[]]);\n}\n\n// Usage with a runtime guard before definition:\nif (roles.length > 0) {\n  const col = singlestoreEnumSafe('role', roles);\n}","typeGuard":"function isNonEmptyStringArray(v: unknown): v is [string, ...string[]] {\n  return Array.isArray(v) && v.every((x) => typeof x === 'string') && v.length > 0;\n}","tryCatchPattern":"try {\n  const col = singlestoreEnum('role', roles as [string, ...string[]]);\n} catch (e) {\n  if (e instanceof Error && /empty array for .* enum values/.test(e.message)) {\n    // supply at least one value or skip defining the column\n  } else throw e;\n}","preventionTips":["Always pass at least one enum value; never call singlestoreEnum with [].","When values are sourced dynamically, validate non-empty before defining the column.","Use a tuple type [string, ...string[]] to encode non-emptiness at the type level."],"tags":["singlestore","enum","validation","schema","configuration"],"analyzedSha":"b7862528fd8fc39bc2653a6c18dad7c1f4e68d10","analyzedAt":"2026-08-03T18:11:14.318Z","schemaVersion":2}