gohugoio/hugo · error
'increment' must not be 0
Error message
'increment' must not be 0
What it means
In the three-argument form of `seq` (FIRST INCREMENT LAST), the middle argument is the step. A zero increment would loop forever, so Hugo rejects it explicitly before computing the sequence size.
Source
Thrown at tpl/collections/collections.go:461
last = first
if last == 0 {
return []int{}, nil
} else if last > 0 {
first = 1
} else {
first = -1
inc = -1
}
} else if len(intArgs) == 2 {
last = intArgs[1]
if last < first {
inc = -1
}
} else {
inc = intArgs[1]
last = intArgs[2]
if inc == 0 {
return nil, errors.New("'increment' must not be 0")
}
if first < last && inc < 0 {
return nil, errors.New("'increment' must be > 0")
}
if first > last && inc > 0 {
return nil, errors.New("'increment' must be < 0")
}
}
// sanity check
if last < -maxSeqSize {
return nil, errSeqSizeExceedsLimit
}
size := ((last - first) / inc) + 1
// sanity check
if size <= 0 || size > maxSeqSize {
return nil, errSeqSizeExceedsLimitView on GitHub ↗ (pinned to 8a468df065)
Solutions
- Pass a non-zero integer increment: `{{ seq 1 2 9 }}`.
- Check argument order — the increment is the second of three arguments.
- If the step comes from a variable, default it: `{{ $inc := default 1 .Params.step }}`.
Example fix
<!-- before -->
{{ seq 1 0 10 }}
<!-- after -->
{{ seq 1 1 10 }} Defensive patterns
Strategy: validation
Validate before calling
{{ if eq $increment 0 }}
{{ errorf "seq increment must be non-zero" }}
{{ else }}
{{ range seq $first $increment $last }}...{{ end }}
{{ end }} Prevention
- Never pass 0 as the middle (increment) argument to the 3-arg seq form.
- If the increment comes from site params, apply `default 1` and reject zero explicitly.
- Watch integer truncation: a computed step like `div 1 2` is 0 in integer math.
When it happens
Trigger: `{{ seq 1 0 10 }}` — three arguments with the second equal to 0, or an increment variable that casts to 0 (e.g. a non-numeric string cast via `cast.ToIntSlice`).
Common situations: Increment sourced from front matter or site params that is unset or a string like "0.5" (which truncates to 0); mixing up the argument order (FIRST INCREMENT LAST, not FIRST LAST STEP).
Related errors
- errKeyIsEmptyString
- %q is not a valid duration unit
- errMustTwoNumbersError
- strings: negative Repeat count
- error correction level must be one of low, medium, quartile,
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/fb7df680a7499257.json.
Report an issue: GitHub ↗.