gohugoio/hugo · error

ellipsis must be a string

Error message

ellipsis must be a string

What it means

Thrown by strings.Truncate when two options are supplied and the first (the ellipsis) cannot be cast to a string (tpl/strings/truncate.go:60-62). In the two-option form the arguments are ellipsis then text, and the ellipsis must be string-convertible.

Solutions

  1. Use the correct order: truncate(length, ellipsis, text) — {{ truncate 50 "…" .Title }}.
  2. If you want the default ellipsis, pass only one option: {{ truncate 50 .Title }}.

Example fix

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

Strategy: validation

Validate before calling

{{ truncate 50 "…" .Title }}

Prevention

When it happens

Trigger: Calling {{ truncate 50 123 .Title }} or {{ truncate 50 .SomeMap .Title }} where options[0] is not string-castable.

Common situations: Swapping argument order so the text lands in the ellipsis slot; passing a number or struct as the ellipsis.

Related errors


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

Appendix: source

Thrown at tpl/strings/truncate.go:62

func (ns *Namespace) Truncate(s any, options ...any) (template.HTML, error) {
	length, err := cast.ToIntE(s)
	if err != nil {
		return "", err
	}
	var textParam any
	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

View on GitHub (pinned to 52c9bd7908)