{"record":{"id":"ed981985e0048d2b","repo":"go-task/task","slug":"enum-reference-q-must-resolve-to-a-list","errorCode":null,"errorMessage":"enum reference %q must resolve to a list","messagePattern":"enum reference %q must resolve to a list","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"variables.go","lineNumber":519,"sourceCode":"\t}\n\treturn resolved, nil\n}\n\nfunc resolveEnumRefs(requires *ast.Requires, cache *templater.Cache) error {\n\tif requires == nil || len(requires.Vars) == 0 {\n\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","sourceCodeStart":501,"sourceCodeEnd":537,"githubUrl":"https://github.com/go-task/task/blob/385e5ad92af02877b6d7cf9dcc963b5ed916e70a/variables.go#L501-L537","documentation":"resolveEnumRefs in variables.go resolves a prompt variable's `enum` reference via templater.ResolveRef and requires the resolved value to be a list. When the referenced variable does not resolve to a list, the library throws this error because interactive prompt choices must come from an array of options.","triggerScenarios":"Declaring a variable with an enum `ref:` (e.g. for prompt variables used by resolveEnumRefForPrompt or compiledTask) where the referenced variable is a scalar, map, or empty value instead of a list.","commonSituations":"Enum ref pointing at a string by mistake, dynamic variable emitting a single JSON value rather than an array, or a rename that changed the variable's type from list to scalar.","solutions":["Change the referenced variable to a list of strings (YAML sequence).","If dynamic, output a JSON array from the command.","Fix the enum ref to point at the correct list variable.","Guard with a pre-run check that the variable is a list before invoking prompts."],"exampleFix":"// before\nvars:\n  ENV: production\nprompt:\n  enum:\n    ref: .ENV\n// after\nvars:\n  ENV: [dev, staging, production]\nprompt:\n  enum:\n    ref: .ENV","handlingStrategy":"validation","validationCode":"func enumSourceIsValid(v any) bool {\n    _, ok := v.([]any)\n    return ok\n}","typeGuard":"func isStringList(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}","tryCatchPattern":"task, err := compiledTask(...)\nif err != nil {\n    if strings.Contains(err.Error(), \"enum reference\") {\n        return fmt.Errorf(\"prompt enum must point at a list of strings: %w\", err)\n    }\n    return err\n}","preventionTips":["Point enum refs only at variables declared as YAML sequences.","Ensure dynamic variables emit JSON arrays of strings.","Validate prompt variable sources before interactive runs.","Keep one canonical list variable per enum and avoid retyping it."],"tags":["taskfile","enum","prompt","validation"],"backgroundTag":"enum-reference-not-a-list","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"}