{"record":{"id":"7335e6b7c7215494","repo":"gohugoio/hugo","slug":"end-argument-must-be-integer","errorCode":null,"errorMessage":"end argument must be integer","messagePattern":"end argument must be integer","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/strings/strings.go","lineNumber":335,"sourceCode":"// The end index can be omitted, it defaults to the string's length.\nfunc (ns *Namespace) SliceString(a any, startEnd ...any) (string, error) {\n\taStr, err := cast.ToStringE(a)\n\tif err != nil {\n\t\treturn \"\", err\n\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","sourceCodeStart":317,"sourceCodeEnd":353,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/strings/strings.go#L317-L353","documentation":"Thrown by strings.SliceString when the end index argument cannot be converted to an int via cast.ToIntE. The end index is the second optional index; a non-integer value (float, word, nil) triggers this.","triggerScenarios":"Calling {{ strings.SliceString $s 0 \"abc\" }}, {{ strings.SliceString $s 1 2.5 }}, or passing a non-integer end index.","commonSituations":"End indices sourced from string front matter; computed float values; nil params.","solutions":["Cast the end to an integer: {{ strings.SliceString $s $start (int $end) }}.","Omit the end argument if you want to slice to the end of the string.","Use numeric front matter."],"exampleFix":"// before\n{{ strings.SliceString $s 0 .Params.end }}\n// after\n{{ strings.SliceString $s 0 (int .Params.end) }}","handlingStrategy":"validation","validationCode":"{{ strings.SliceString $s $start (int $end) }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Cast the end index to int.","Omit the end index to slice to the string end.","Use numeric front matter."],"tags":["template","strings","type-conversion","hugo"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}