{"record":{"id":"b97cbb66ca8bb2d5","repo":"gohugoio/hugo","slug":"start-argument-must-be-integer","errorCode":null,"errorMessage":"start argument must be integer","messagePattern":"start argument must be integer","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/strings/strings.go","lineNumber":330,"sourceCode":"\treturn replacer.Replace(ss), nil\n}\n\n// SliceString slices a string by specifying a half-open range with\n// two indices, start and end. 1 and 4 creates a slice including elements 1 through 3.\n// 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","sourceCodeStart":312,"sourceCodeEnd":348,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/strings/strings.go#L312-L348","documentation":"Thrown by strings.SliceString when the start index argument cannot be converted to an int via cast.ToIntE. SliceString takes a string and up to two integer indices; a non-integer start (a float, a word, nil) triggers this.","triggerScenarios":"Calling {{ strings.SliceString $s \"abc\" }}, {{ strings.SliceString $s 1.5 }}, or {{ strings.SliceString $s $nil }} where the start is non-integer.","commonSituations":"Index values coming from front matter as strings; float indices from computed values; nil params used as indices.","solutions":["Cast the start to an integer: {{ strings.SliceString $s (int $start) }}.","Default the start: {{ strings.SliceString $s ($start | default 0) }}.","Use numeric front matter for index fields."],"exampleFix":"// before\n{{ strings.SliceString $s .Params.start }}\n// after\n{{ strings.SliceString $s (int .Params.start) }}","handlingStrategy":"validation","validationCode":"{{ strings.SliceString $s (int $start) }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Cast index params to int.","Default nil indices to 0.","Use numeric front matter for index fields."],"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"}