gohugoio/hugo · error

invalid number of arguments to Seq

Error message

invalid number of arguments to Seq

What it means

The `seq` template function mimics GNU seq and accepts 1–3 arguments: LAST, FIRST LAST, or FIRST INCREMENT LAST. Calling it with zero arguments or more than three fails this arity check before any parsing happens.

Source

Thrown at tpl/collections/collections.go:430

}

// Sanity check for slices created by Seq and D.
const maxSeqSize = 1000000

var errSeqSizeExceedsLimit = errors.New("size of result exceeds limit")

// Seq creates a sequence of integers from args. It's named and used as GNU's seq.
//
// Examples:
//
//	3 => 1, 2, 3
//	1 2 4 => 1, 3
//	-3 => -1, -2, -3
//	1 4 => 1, 2, 3, 4
//	1 -2 => 1, 0, -1, -2
func (ns *Namespace) Seq(args ...any) ([]int, error) {
	if len(args) < 1 || len(args) > 3 {
		return nil, errors.New("invalid number of arguments to Seq")
	}

	intArgs := cast.ToIntSlice(args)
	if len(intArgs) < 1 || len(intArgs) > 3 {
		return nil, errors.New("invalid arguments to Seq")
	}

	inc := 1
	var last int
	first := intArgs[0]

	if len(intArgs) == 1 {
		last = first
		if last == 0 {
			return []int{}, nil
		} else if last > 0 {
			first = 1
		} else {

View on GitHub ↗ (pinned to 8a468df065)

Solutions

  1. Call with 1–3 integer arguments: `{{ seq 5 }}`, `{{ seq 1 5 }}`, or `{{ seq 1 2 9 }}`.
  2. If the argument comes from a param, guard against it being missing: `{{ with .Params.count }}{{ seq . }}{{ end }}`.

Example fix

<!-- before -->
{{ range seq }}...{{ end }}
<!-- after -->
{{ range seq 1 .Params.count }}...{{ end }}
Defensive patterns

Strategy: validation

Validate before calling

{{/* seq takes 1..3 args: seq LAST | seq FIRST LAST | seq FIRST INCREMENT LAST */}}
{{ $args := slice $first $step $last }}
{{ if or (lt (len $args) 1) (gt (len $args) 3) }}{{ errorf "seq needs 1-3 args" }}{{ end }}

Prevention

When it happens

Trigger: `{{ seq }}` with no arguments, or `{{ seq 1 2 3 4 }}` with four or more; also passing a slice that spreads into too many args.

Common situations: Forgetting to pass the count variable (empty/undefined param evaluated away); confusing `seq`'s signature with `range` over a collection; extra whitespace-split arguments in a partial call.

Related errors


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