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 int

View on GitHub ↗ (pinned to 8a468df065)

Solutions

  1. Reduce to `truncate LENGTH [ELLIPSIS] TEXT` — remove the extra argument
  2. When piping, don't also pass the text explicitly: use `{{ .Summary | truncate 30 "..." }}`
  3. 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

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


AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31). Data as JSON: /data/errors/abac42b0081418ce.json. Report an issue: GitHub ↗.