gohugoio/hugo · error

too many arguments

Error message

too many arguments

What it means

`strings.SliceString` accepts at most two index arguments after the string (start and end). If more than two variadic arguments are supplied, Hugo rejects the call outright rather than ignoring the extras.

Source

Thrown at tpl/strings/strings.go:340

	}

	var argStart, argEnd int

	argNum := len(startEnd)

	if argNum > 0 {
		if argStart, err = cast.ToIntE(startEnd[0]); err != nil {
			return "", errors.New("start argument must be integer")
		}
	}
	if argNum > 1 {
		if argEnd, err = cast.ToIntE(startEnd[1]); err != nil {
			return "", errors.New("end argument must be integer")
		}
	}

	if argNum > 2 {
		return "", errors.New("too many arguments")
	}

	asRunes := []rune(aStr)

	if argNum > 0 && (argStart < 0 || argStart >= len(asRunes)) {
		return "", errors.New("slice bounds out of range")
	}

	if argNum == 2 {
		if argEnd < 0 || argEnd > len(asRunes) {
			return "", errors.New("slice bounds out of range")
		}
		return string(asRunes[argStart:argEnd]), nil
	} else if argNum == 1 {
		return string(asRunes[argStart:]), nil
	} else {
		return string(asRunes[:]), nil
	}

View on GitHub ↗ (pinned to 8a468df065)

Solutions

  1. Remove the extra arguments — use only `slicestr STRING [START] [END]`
  2. If you meant `substr` (start + length), use `{{ substr $s 0 3 }}` instead
  3. When piping, remember the piped value is the final argument: `{{ "BatMan" | slicestr 0 3 }}` is already three args

Example fix

// before
{{ slicestr "BatMan" 0 3 5 }}
// after
{{ slicestr "BatMan" 0 3 }}
Defensive patterns

Strategy: validation

Validate before calling

{{/* substr accepts at most (string, start, end) — 3 args */}}
{{ substr .s .start .end }}

Try / catch

{{ with try (substr .s .start .end) }}{{ if .Err }}{{ errorf "bad substr call: %s" .Err }}{{ end }}{{ end }}

Prevention

When it happens

Trigger: Calling `slicestr` with four or more total arguments: `{{ slicestr "BatMan" 0 3 5 }}`, or piping a value into a call that already has three arguments (`{{ $s | slicestr 0 3 5 }}`).

Common situations: Confusing `slicestr` with a step-supporting slice syntax from Python; forgetting that a piped value counts as an argument; accidentally passing a spread of values from `range` or `slice`.

Related errors


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