{"record":{"id":"6aedc6734dd26ab1","repo":"gohugoio/hugo","slug":"too-many-slice-indexes-d","errorCode":null,"errorMessage":"too many slice indexes: %d","messagePattern":"too many slice indexes: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/internal/go_templates/texttemplate/funcs.go","lineNumber":252,"sourceCode":"}\n\n// Slicing.\n\n// slice returns the result of slicing its first argument by the remaining\n// arguments. Thus \"slice x 1 2\" is, in Go syntax, x[1:2], while \"slice x\"\n// is x[:], \"slice x 1\" is x[1:], and \"slice x 1 2 3\" is x[1:2:3]. The first\n// argument must be a string, slice, or array.\nfunc slice(item reflect.Value, indexes ...reflect.Value) (reflect.Value, error) {\n\titem = indirectInterface(item)\n\tif !item.IsValid() {\n\t\treturn reflect.Value{}, fmt.Errorf(\"slice of untyped nil\")\n\t}\n\tvar isNil bool\n\tif item, isNil = indirect(item); isNil {\n\t\treturn reflect.Value{}, fmt.Errorf(\"slice of nil pointer\")\n\t}\n\tif len(indexes) > 3 {\n\t\treturn reflect.Value{}, fmt.Errorf(\"too many slice indexes: %d\", len(indexes))\n\t}\n\tvar cap int\n\tswitch item.Kind() {\n\tcase reflect.String:\n\t\tif len(indexes) == 3 {\n\t\t\treturn reflect.Value{}, fmt.Errorf(\"cannot 3-index slice a string\")\n\t\t}\n\t\tcap = item.Len()\n\tcase reflect.Array, reflect.Slice:\n\t\tcap = item.Cap()\n\tdefault:\n\t\treturn reflect.Value{}, fmt.Errorf(\"can't slice item of type %s\", item.Type())\n\t}\n\t// set default values for cases item[:], item[i:].\n\tidx := [3]int{0, item.Len()}\n\tfor i, index := range indexes {\n\t\tx, err := indexArg(index, cap)\n\t\tif err != nil {","sourceCodeStart":234,"sourceCodeEnd":270,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/internal/go_templates/texttemplate/funcs.go#L234-L270","documentation":"Raised by the `slice` action when more than three index arguments are supplied (funcs.go:251-252). `slice` supports at most the three-index form `s[i:j:k]` (Go 3-index slice expression); four or more operands have no valid Go semantics.","triggerScenarios":"`{{slice .X 1 2 3 4}}`, or a typo/extra trailing argument; programmatic template generation that appends an extra index.","commonSituations":"Misunderstanding that `slice` mirrors Go's `[i:j:k]` and assumes a maximum of three operands; copy-paste errors; confused with `index` which accepts arbitrary chaining.","solutions":["Reduce to at most three indexes: `{{slice .X 1 2 3}}`.","If you meant nested indexing use `{{index .X 1 2 3}}` instead of `slice`.","Check the template source for stray arguments."],"exampleFix":"// before\n{{slice .S 0 2 4 6}}\n\n// after\n{{slice .S 0 2 4}}","handlingStrategy":"validation","validationCode":"// Limit slice arity in template authoring — at most 3 indexes:\n//   {{slice .S 0 2 4}}\n// If building templates programmatically, cap indexes to len<=3.","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember slice mirrors Go's [i:j:k] — max 3 operands.","Use index (not slice) for nested element access.","Lint generated templates for slice actions with >3 args."],"tags":["template","slice","text-template"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}