{"record":{"id":"4f79ab9e3a8f18e9","repo":"gohugoio/hugo","slug":"too-few-arguments","errorCode":null,"errorMessage":"too few arguments","messagePattern":"too few arguments","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/strings/strings.go","lineNumber":396,"sourceCode":"// To extract characters from the end of the string, use a negative start number.\n//\n// In addition, borrowing from the extended behavior described at http://php.net/substr,\n// if length is given and is negative, then that many characters will be omitted from\n// the end of string.\nfunc (ns *Namespace) Substr(a any, nums ...any) (string, error) {\n\ts, err := cast.ToStringE(a)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\tasRunes := []rune(s)\n\trlen := len(asRunes)\n\n\tvar start, length int\n\n\tswitch len(nums) {\n\tcase 0:\n\t\treturn \"\", errors.New(\"too few arguments\")\n\tcase 1:\n\t\tif start, err = cast.ToIntE(nums[0]); err != nil {\n\t\t\treturn \"\", errors.New(\"start argument must be an integer\")\n\t\t}\n\t\tlength = rlen\n\tcase 2:\n\t\tif start, err = cast.ToIntE(nums[0]); err != nil {\n\t\t\treturn \"\", errors.New(\"start argument must be an integer\")\n\t\t}\n\t\tif length, err = cast.ToIntE(nums[1]); err != nil {\n\t\t\treturn \"\", errors.New(\"length argument must be an integer\")\n\t\t}\n\tdefault:\n\t\treturn \"\", errors.New(\"too many arguments\")\n\t}\n\n\tif rlen == 0 {\n\t\treturn \"\", nil","sourceCodeStart":378,"sourceCodeEnd":414,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/strings/strings.go#L378-L414","documentation":"Thrown by strings.Substr when called with no numeric arguments after the string. Substr requires at least a start index; calling it with only the string (zero extra args) is a usage error. (This is distinct from SliceString which permits zero indices.)","triggerScenarios":"Calling {{ strings.Substr $s }} with no start index, or piping a string into Substr without an index: {{ $s | strings.Substr }}.","commonSituations":"Confusing Substr with a no-arg function; refactoring that dropped the start argument; piping where the index was expected positionally.","solutions":["Always provide at least a start index: {{ strings.Substr $s $start }}.","Use strings.SliceString $s (no indices) if you want the whole string.","Double-check the call after refactors that move arguments."],"exampleFix":"// before\n{{ strings.Substr $s }}\n// after\n{{ strings.Substr $s 0 }}","handlingStrategy":"validation","validationCode":"{{ strings.Substr $s 0 }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass at least a start index to Substr.","Use strings.SliceString with no indices to return the whole string.","Double-check Substr calls after refactors."],"tags":["template","strings","arguments","hugo"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}