{"record":{"id":"abac42b0081418ce","repo":"gohugoio/hugo","slug":"too-many-arguments-passed-to-truncate","errorCode":null,"errorMessage":"too many arguments passed to truncate","messagePattern":"too many arguments passed to truncate","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/strings/truncate.go","lineNumber":68,"sourceCode":"\tvar ellipsis string\n\n\tswitch len(options) {\n\tcase 0:\n\t\treturn \"\", errors.New(\"truncate requires a length and a string\")\n\tcase 1:\n\t\ttextParam = options[0]\n\t\tellipsis = \" …\"\n\tcase 2:\n\t\ttextParam = options[1]\n\t\tellipsis, err = cast.ToStringE(options[0])\n\t\tif err != nil {\n\t\t\treturn \"\", errors.New(\"ellipsis must be a string\")\n\t\t}\n\t\tif _, ok := options[0].(template.HTML); !ok {\n\t\t\tellipsis = html.EscapeString(ellipsis)\n\t\t}\n\tdefault:\n\t\treturn \"\", errors.New(\"too many arguments passed to truncate\")\n\t}\n\n\ttext, err := cast.ToStringE(textParam)\n\tif err != nil {\n\t\treturn \"\", errors.New(\"text must be a string\")\n\t}\n\n\t_, isHTML := textParam.(template.HTML)\n\n\tif utf8.RuneCountInString(text) <= length {\n\t\tif isHTML {\n\t\t\treturn template.HTML(text), nil\n\t\t}\n\t\treturn template.HTML(html.EscapeString(text)), nil\n\t}\n\n\ttags := []htmlTag{}\n\tvar lastWordIndex, lastNonSpace, currentLen, endTextPos, nextTag int","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/strings/truncate.go#L50-L86","documentation":"Thrown by strings.Truncate when more than two options are supplied (tpl/strings/truncate.go:67-68, the default case). Truncate accepts at most an ellipsis and the text beyond the length; any further positional argument is rejected.","triggerScenarios":"Calling {{ truncate 50 \"…\" .Title .Extra }} with three or more options.","commonSituations":"Assuming Truncate takes extra config flags; passing both a plain-text and HTML variant; leftover arguments from refactoring.","solutions":["Remove the extra argument; Truncate only takes (length[, ellipsis], text).","Pre-process the text before truncating instead of passing extra options."],"exampleFix":"// before\n{{ truncate 50 \"…\" .Title .Suffix }}\n// after\n{{ truncate 50 \"…\" .Title }}","handlingStrategy":"validation","validationCode":"{{ truncate 50 \"…\" .Title }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Truncate accepts at most (length, ellipsis, text).","Pre-process text rather than adding extra args."],"tags":["template-function","strings","truncate","arity","argument"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}