gohugoio/hugo · error

too many arguments passed to truncate

Error message

too many arguments passed to truncate

What it means

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.

Solutions

  1. Remove the extra argument; Truncate only takes (length[, ellipsis], text).
  2. Pre-process the text before truncating instead of passing extra options.

Example fix

// before
{{ truncate 50 "…" .Title .Suffix }}
// after
{{ truncate 50 "…" .Title }}
Defensive patterns

Strategy: validation

Validate before calling

{{ truncate 50 "…" .Title }}

Prevention

When it happens

Trigger: Calling {{ truncate 50 "…" .Title .Extra }} with three or more options.

Common situations: Assuming Truncate takes extra config flags; passing both a plain-text and HTML variant; leftover arguments from refactoring.

Related errors


AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09). Data as JSON: /api/errors/abac42b0081418ce. Report an issue: GitHub.

Appendix: 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 52c9bd7908)