gohugoio/hugo · error
sequence bounds out of range [{nv}:]
Error message
sequence bounds out of range [{nv}:] What it means
After (collections.go:75-77) rejects a negative offset because Go slice bounds cannot be negative. The offending numeric value is interpolated into the message.
Source
Thrown at tpl/collections/collections.go:76
loc *time.Location
sortComp *compare.Namespace
dCache *hmaps.Cache[dKey, []int]
deps *deps.Deps
}
// After returns all the items after the first n items in list l.
func (ns *Namespace) After(n any, l any) (any, error) {
if n == nil || l == nil {
return nil, errors.New("both limit and seq must be provided")
}
nv, err := cast.ToIntE(n)
if err != nil {
return nil, err
}
if nv < 0 {
return nil, errors.New("sequence bounds out of range [" + cast.ToString(nv) + ":]")
}
lv := reflect.ValueOf(l)
lv, isNil := hreflect.Indirect(lv)
if isNil {
return nil, errors.New("can't iterate over a nil value")
}
switch lv.Kind() {
case reflect.Array, reflect.Slice, reflect.String:
// okay
default:
return nil, errors.New("can't iterate over " + reflect.ValueOf(l).Type().String())
}
if nv >= lv.Len() {
return lv.Slice(0, 0).Interface(), nil
}View on GitHub (pinned to 52c9bd7908)
Solutions
- Clamp the offset to >= 0: {{ after (math.Max 0 $n) .Pages }}
- Guard: {{ if ge $n 0 }}{{ after $n .Pages }}{{ end }}
- Use (cond (lt $n 0) 0 $n) to coerce
Example fix
// before
{{ after (sub $a $b) .Pages }}
// after
{{ after (math.Max 0 (sub $a $b)) .Pages }} Defensive patterns
Strategy: validation
Validate before calling
{{ $n := math.Max 0 $n }}
{{ after $n .Pages }} Prevention
- Clamp computed offsets with math.Max 0 before calling after
- Validate user-supplied offsets are >= 0
- Guard subtraction results that can go negative
When it happens
Trigger: {{ after -1 .Pages }} or any computed offset that goes below zero (e.g. {{ after (sub $a $b) .Pages }} where b > a).
Common situations: Subtracting too much when deriving an offset; user-controlled param passed through without clamping; off-by-one in pagination math.
Related errors
- sequence length must be non-negative
- the number of requested values (%v) must be a non-negative i
- the maximum requested value (%v) must be a non-negative inte
- need at least 2 arguments to append
- can't apply myself (no turtles allowed)
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/efc7c643fbd9e4ee.
Report an issue: GitHub.