{"record":{"id":"8a023d8a7ca8a79d","repo":"go-task/task","slug":"enum-reference-q-must-contain-only-strings","errorCode":null,"errorMessage":"enum reference %q must contain only strings","messagePattern":"enum reference %q must contain only strings","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"variables.go","lineNumber":525,"sourceCode":"\t\treturn nil\n\t}\n\tfor _, v := range requires.Vars {\n\t\tif v.Enum == nil || v.Enum.Ref == \"\" {\n\t\t\tcontinue\n\t\t}\n\t\tresolved := templater.ResolveRef(v.Enum.Ref, cache)\n\t\tif cache.Err() != nil {\n\t\t\treturn cache.Err()\n\t\t}\n\t\tarr, ok := resolvedAsAnySlice(resolved)\n\t\tif !ok {\n\t\t\treturn fmt.Errorf(\"enum reference %q must resolve to a list\", v.Enum.Ref)\n\t\t}\n\t\tstrValues := make([]string, 0, len(arr))\n\t\tfor _, item := range arr {\n\t\t\ts, ok := item.(string)\n\t\t\tif !ok {\n\t\t\t\treturn fmt.Errorf(\"enum reference %q must contain only strings\", v.Enum.Ref)\n\t\t\t}\n\t\t\tstrValues = append(strValues, s)\n\t\t}\n\t\tv.Enum.Value = strValues\n\t}\n\treturn nil\n}\n\n// product generates the cartesian product of the input map of slices.\nfunc product(matrix *ast.Matrix) []map[string]any {\n\tif matrix.Len() == 0 {\n\t\treturn nil\n\t}\n\n\t// Start with an empty product result\n\tresult := []map[string]any{{}}\n\n\t// Iterate over each slice in the slices","sourceCodeStart":507,"sourceCodeEnd":543,"githubUrl":"https://github.com/go-task/task/blob/385e5ad92af02877b6d7cf9dcc963b5ed916e70a/variables.go#L507-L543","documentation":"resolveEnumRefs in variables.go validates every element of a resolved enum list and requires all items to be strings. If any element is a number, boolean, map, or other non-string type, the library throws this error because prompt enum choices are rendered and compared as strings.","triggerScenarios":"An enum ref resolves to a list containing non-string items, e.g. ENV: [1, 2, 3] or [true, false], used by a prompt variable's enum during compiledTask or resolveEnumRefForPrompt.","commonSituations":"Port numbers or versions written as YAML integers, booleans in a feature-flag enum, dynamic variables returning JSON arrays of numbers.","solutions":["Quote every element in the YAML list so it parses as a string (e.g. ['1', '2']).","If dynamic, make the command emit an array of JSON strings.","Convert numeric items at the source, e.g. JSON: [\"8080\", \"9090\"].","Keep enum lists string-only by convention in the taskfile."],"exampleFix":"// before\nvars:\n  PORTS: [8080, 9090]\nprompt:\n  enum:\n    ref: .PORTS\n// after\nvars:\n  PORTS: ['8080', '9090']\nprompt:\n  enum:\n    ref: .PORTS","handlingStrategy":"type-guard","validationCode":"func allStrings(v any) bool {\n    arr, ok := v.([]any)\n    if !ok { return false }\n    for _, item := range arr {\n        if _, ok := item.(string); !ok { return false }\n    }\n    return true\n}\n// pre-check: allStrings(mustResolve(envVarRef))","typeGuard":"func asStringList(v any) ([]string, bool) {\n    arr, ok := v.([]any)\n    if !ok { return nil, false }\n    out := make([]string, 0, len(arr))\n    for _, item := range arr {\n        s, ok := item.(string)\n        if !ok { return nil, false }\n        out = append(out, s)\n    }\n    return out, true\n}","tryCatchPattern":"task, err := compiledTask(...)\nif err != nil {\n    if strings.Contains(err.Error(), \"must contain only strings\") {\n        return fmt.Errorf(\"quote enum values as strings in the taskfile: %w\", err)\n    }\n    return err\n}","preventionTips":["Always quote enum list items in YAML ('8080', 'true') so they parse as strings.","For dynamic variables, emit JSON arrays of strings only.","Run a pre-run lint that every enum source is a []string.","Avoid mixing numeric and string items in prompt choice lists."],"tags":["taskfile","enum","prompt","type-error"],"backgroundTag":"enum-items-not-strings","analyzedSha":"385e5ad92af02877b6d7cf9dcc963b5ed916e70a","analyzedAt":"2026-09-05T09:01:05.226Z","contentChangedAt":"2026-09-05T09:01:05.226Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}