{"id":"89e289404fb55ce0","repo":"gohugoio/hugo","slug":"too-many-arguments","errorCode":null,"errorMessage":"too many arguments","messagePattern":"too many arguments","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/strings/strings.go","lineNumber":340,"sourceCode":"\t}\n\n\tvar argStart, argEnd int\n\n\targNum := len(startEnd)\n\n\tif argNum > 0 {\n\t\tif argStart, err = cast.ToIntE(startEnd[0]); err != nil {\n\t\t\treturn \"\", errors.New(\"start argument must be integer\")\n\t\t}\n\t}\n\tif argNum > 1 {\n\t\tif argEnd, err = cast.ToIntE(startEnd[1]); err != nil {\n\t\t\treturn \"\", errors.New(\"end argument must be integer\")\n\t\t}\n\t}\n\n\tif argNum > 2 {\n\t\treturn \"\", errors.New(\"too many arguments\")\n\t}\n\n\tasRunes := []rune(aStr)\n\n\tif argNum > 0 && (argStart < 0 || argStart >= len(asRunes)) {\n\t\treturn \"\", errors.New(\"slice bounds out of range\")\n\t}\n\n\tif argNum == 2 {\n\t\tif argEnd < 0 || argEnd > len(asRunes) {\n\t\t\treturn \"\", errors.New(\"slice bounds out of range\")\n\t\t}\n\t\treturn string(asRunes[argStart:argEnd]), nil\n\t} else if argNum == 1 {\n\t\treturn string(asRunes[argStart:]), nil\n\t} else {\n\t\treturn string(asRunes[:]), nil\n\t}","sourceCodeStart":322,"sourceCodeEnd":358,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/tpl/strings/strings.go#L322-L358","documentation":"`strings.SliceString` accepts at most two index arguments after the string (start and end). If more than two variadic arguments are supplied, Hugo rejects the call outright rather than ignoring the extras.","triggerScenarios":"Calling `slicestr` with four or more total arguments: `{{ slicestr \"BatMan\" 0 3 5 }}`, or piping a value into a call that already has three arguments (`{{ $s | slicestr 0 3 5 }}`).","commonSituations":"Confusing `slicestr` with a step-supporting slice syntax from Python; forgetting that a piped value counts as an argument; accidentally passing a spread of values from `range` or `slice`.","solutions":["Remove the extra arguments — use only `slicestr STRING [START] [END]`","If you meant `substr` (start + length), use `{{ substr $s 0 3 }}` instead","When piping, remember the piped value is the final argument: `{{ \"BatMan\" | slicestr 0 3 }}` is already three args"],"exampleFix":"// before\n{{ slicestr \"BatMan\" 0 3 5 }}\n// after\n{{ slicestr \"BatMan\" 0 3 }}","handlingStrategy":"validation","validationCode":"{{/* substr accepts at most (string, start, end) — 3 args */}}\n{{ substr .s .start .end }}","typeGuard":null,"tryCatchPattern":"{{ with try (substr .s .start .end) }}{{ if .Err }}{{ errorf \"bad substr call: %s\" .Err }}{{ end }}{{ end }}","preventionTips":["Check the substr signature: string, start, optional end — never more than two numeric arguments.","When piping (`.s | substr 1 2`), remember the piped value becomes the last argument; don't also pass the string explicitly.","Fail fast in CI: run `hugo --logLevel warn` builds so extra-argument mistakes surface immediately."],"tags":["hugo","templates","strings","arguments"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}