gohugoio/hugo · error
too many arguments passed to truncate
Error message
too many arguments passed to truncate
What it means
`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.
Source
Thrown at tpl/strings/truncate.go:68
var ellipsis string
switch len(options) {
case 0:
return "", errors.New("truncate requires a length and a string")
case 1:
textParam = options[0]
ellipsis = " …"
case 2:
textParam = options[1]
ellipsis, err = cast.ToStringE(options[0])
if err != nil {
return "", errors.New("ellipsis must be a string")
}
if _, ok := options[0].(template.HTML); !ok {
ellipsis = html.EscapeString(ellipsis)
}
default:
return "", errors.New("too many arguments passed to truncate")
}
text, err := cast.ToStringE(textParam)
if err != nil {
return "", errors.New("text must be a string")
}
_, isHTML := textParam.(template.HTML)
if utf8.RuneCountInString(text) <= length {
if isHTML {
return template.HTML(text), nil
}
return template.HTML(html.EscapeString(text)), nil
}
tags := []htmlTag{}
var lastWordIndex, lastNonSpace, currentLen, endTextPos, nextTag intView on GitHub ↗ (pinned to 8a468df065)
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
Example fix
// before
{{ .Summary | truncate 30 "..." .Title }}
// after
{{ .Summary | truncate 30 "..." }} Defensive patterns
Strategy: validation
Validate before calling
{{/* truncate takes at most: length, ellipsis, text */}}
{{ truncate 70 "…" .Summary }} Try / catch
{{ with try (truncate 70 "…" .Summary) }}{{ if .Err }}{{ errorf "truncate arity: %s" .Err }}{{ end }}{{ end }} Prevention
- 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.
When it happens
Trigger: `{{ truncate 30 "..." .Summary "extra" }}`, or piping into an already-full call: `{{ .Summary | truncate 30 "..." .Other }}` where the piped value becomes a fourth argument.
Common situations: 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.
Related errors
- truncate requires a length and a string
- ellipsis must be a string
- need at least 2 arguments to append
- must provide a Resource and optionally an options map
- operator argument must be string type
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/abac42b0081418ce.json.
Report an issue: GitHub ↗.