{"id":"6cd6b350bfd5c05a","repo":"gohugoio/hugo","slug":"errseqsizeexceedslimit","errorCode":"errSeqSizeExceedsLimit","errorMessage":"size of result exceeds limit","messagePattern":"size of result exceeds limit","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/collections/collections.go","lineNumber":417,"sourceCode":"\tcase reflect.Slice:\n\tdefault:\n\t\treturn nil, errors.New(\"argument must be a slice\")\n\t}\n\n\tsliceCopy := reflect.MakeSlice(v.Type(), v.Len(), v.Len())\n\n\tfor i := v.Len() - 1; i >= 0; i-- {\n\t\telement := sliceCopy.Index(i)\n\t\telement.Set(v.Index(v.Len() - 1 - i))\n\t}\n\n\treturn sliceCopy.Interface(), nil\n}\n\n// Sanity check for slices created by Seq and D.\nconst maxSeqSize = 1000000\n\nvar errSeqSizeExceedsLimit = errors.New(\"size of result exceeds limit\")\n\n// Seq creates a sequence of integers from args. It's named and used as GNU's seq.\n//\n// Examples:\n//\n//\t3 => 1, 2, 3\n//\t1 2 4 => 1, 3\n//\t-3 => -1, -2, -3\n//\t1 4 => 1, 2, 3, 4\n//\t1 -2 => 1, 0, -1, -2\nfunc (ns *Namespace) Seq(args ...any) ([]int, error) {\n\tif len(args) < 1 || len(args) > 3 {\n\t\treturn nil, errors.New(\"invalid number of arguments to Seq\")\n\t}\n\n\tintArgs := cast.ToIntSlice(args)\n\tif len(intArgs) < 1 || len(intArgs) > 3 {\n\t\treturn nil, errors.New(\"invalid arguments to Seq\")","sourceCodeStart":399,"sourceCodeEnd":435,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/tpl/collections/collections.go#L399-L435","documentation":"Hugo caps sequences produced by the `seq` (and `collections.D`) functions at `maxSeqSize` = 1,000,000 elements as a sanity check. If the computed size `((last-first)/inc)+1` exceeds that limit, is non-positive, or the bound is below -1,000,000, `errSeqSizeExceedsLimit` is returned to prevent runaway memory allocation during a build.","triggerScenarios":"`{{ seq 2000000 }}`, `{{ seq 1 10000000 }}`, or any first/last/increment combination whose element count exceeds 1,000,000 (or underflows below -1,000,000).","commonSituations":"Using `seq` with a large computed value from `.Params` or site data (e.g. a timestamp or byte count mistakenly used as a count); generating paginated ranges from unbounded user data.","solutions":["Reduce the range so the result has ≤ 1,000,000 elements, e.g. clamp with `math.Min`.","Check whether the bound variable holds what you expect (`printf \"%d\"`) — a timestamp or ID often sneaks in.","Restructure the template to avoid materializing huge ranges; use pagination or `first`/`after` on real collections."],"exampleFix":"<!-- before -->\n{{ range seq $bigCount }}...{{ end }}\n<!-- after -->\n{{ range seq (math.Min $bigCount 1000) }}...{{ end }}","handlingStrategy":"validation","validationCode":"{{/* seq result is capped (~2000 elements); check span first */}}\n{{ $n := sub $last $first }}\n{{ if gt $n 2000 }}\n  {{ errorf \"seq range too large: %d\" $n }}\n{{ else }}\n  {{ range seq $first $last }}...{{ end }}\n{{ end }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep seq ranges small — it's meant for pagination-scale loops, not large numeric ranges.","Compute the element count ((last-first)/step + 1) before calling seq when arguments are dynamic.","For iterating over content, range the page collection directly instead of generating index sequences."],"tags":["hugo","templates","seq","limits","memory"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}