{"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/8a468df065a75c1c7cf9f6850f32148746590ea5/tpl/strings/truncate.go#L50-L86","documentation":"`truncate` accepts at most two options after the length: an optional ellipsis and the text (so three arguments total). A fourth argument hits the switch default and aborts with this error rather than silently ignoring extras.","triggerScenarios":"`{{ truncate 30 \"...\" .Summary \"extra\" }}`, or piping into an already-full call: `{{ .Summary | truncate 30 \"...\" .Other }}` where the piped value becomes a fourth argument.","commonSituations":"Forgetting the piped value counts as the last argument; trying to pass extra flags (e.g. a word-boundary or HTML option that doesn't exist); copy-paste from other templating languages whose truncate filters take more parameters.","solutions":["Reduce to `truncate LENGTH [ELLIPSIS] TEXT` — remove the extra argument","When piping, don't also pass the text explicitly: use `{{ .Summary | truncate 30 \"...\" }}`","If you need more control (word count, plain text), look at `truncate` on `.Summary`/`plainify` combinations instead of extra args"],"exampleFix":"// before\n{{ .Summary | truncate 30 \"...\" .Title }}\n// after\n{{ .Summary | truncate 30 \"...\" }}","handlingStrategy":"validation","validationCode":"{{/* truncate takes at most: length, ellipsis, text */}}\n{{ truncate 70 \"…\" .Summary }}","typeGuard":null,"tryCatchPattern":"{{ with try (truncate 70 \"…\" .Summary) }}{{ if .Err }}{{ errorf \"truncate arity: %s\" .Err }}{{ end }}{{ end }}","preventionTips":["Truncate accepts at most three arguments (length, ellipsis, text); trim any extras.","In pipe form the piped value is appended as the final argument — don't also pass the text explicitly, or you'll exceed the arity.","Catch these statically by building the site in CI with warnings treated as failures."],"tags":["hugo","templates","truncate","arguments"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}