{"id":"85f26cc7ff58a146","repo":"go-redis/redis","slug":"redis-invalid-timeseries-aggregator-at-index-d-85f26c","errorCode":null,"errorMessage":"redis: invalid timeseries aggregator at index %d[%d]: Invalid (%d)","messagePattern":"redis: invalid timeseries aggregator at index (.+?)\\[(.+?)\\]: Invalid \\((.+?)\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"timeseries_commands.go","lineNumber":1387,"sourceCode":"}\n\n// buildNRangeAggregationArgs validates and returns one aggregator spec string per key for\n// TS.NRANGE / TS.NREVRANGE. The number of specs must equal the number of keys. Each spec\n// lists one or more aggregators for its key and is emitted as a single comma-joined wire\n// token; specs for different keys are separate wire tokens.\nfunc buildNRangeAggregationArgs(keys []string, aggregators [][]Aggregator) ([]string, error) {\n\tif len(aggregators) != len(keys) {\n\t\treturn nil, fmt.Errorf(\"redis: TS.NRANGE/TS.NREVRANGE requires exactly %d aggregator spec(s), got %d\", len(keys), len(aggregators))\n\t}\n\tparts := make([]string, len(aggregators))\n\tfor i, spec := range aggregators {\n\t\tif len(spec) == 0 {\n\t\t\treturn nil, fmt.Errorf(\"redis: empty timeseries aggregator spec at index %d\", i)\n\t\t}\n\t\tnames := make([]string, len(spec))\n\t\tfor j, agg := range spec {\n\t\t\tif agg == Invalid {\n\t\t\t\treturn nil, fmt.Errorf(\"redis: invalid timeseries aggregator at index %d[%d]: Invalid (%d)\", i, j, agg)\n\t\t\t}\n\t\t\ts := agg.String()\n\t\t\tif s == \"\" {\n\t\t\t\treturn nil, fmt.Errorf(\"redis: invalid timeseries aggregator at index %d[%d]: %d\", i, j, agg)\n\t\t\t}\n\t\t\tnames[j] = s\n\t\t}\n\t\tparts[i] = strings.Join(names, \",\")\n\t}\n\treturn parts, nil\n}\n\n// appendNRangeOptions appends optional TS.NRANGE / TS.NREVRANGE arguments to args.\nfunc appendNRangeOptions(\n\targs []interface{},\n\tkeys []string,\n\tlatest bool,\n\tfilterByTS []int,","sourceCodeStart":1369,"sourceCodeEnd":1405,"githubUrl":"https://github.com/go-redis/redis/blob/36d97525cd8076aed67cddf54778e9ea84550929/timeseries_commands.go#L1369-L1405","documentation":"Returned by buildNRangeAggregationArgs when an element inside a per-key aggregator spec equals the Invalid constant (0). The message reports both the outer spec index i and the inner position [j], plus the Invalid value, to pinpoint the offending entry.","triggerScenarios":"Passing Aggregators where some inner []Aggregator contains redis.Invalid or a zero-value element, e.g. [][]Aggregator{{redis.Invalid}}.","commonSituations":"Allocating an inner slice with make([]redis.Aggregator, k) and only partially filling it, or merging specs from a source that uses 0 as a no-op.","solutions":["Replace or remove any redis.Invalid entry inside each spec.","Filter inner slices before the call: spec = slices.DeleteFunc(spec, func(a redis.Aggregator) bool { return a == redis.Invalid }).","Use append to build inner specs so only explicitly-set values are included."],"exampleFix":"// before\nopts := &redis.TSNRangeOptions{\n    Aggregators: [][]redis.Aggregator{{redis.Avg, redis.Invalid}},\n}\n\n// after\nopts := &redis.TSNRangeOptions{\n    Aggregators: [][]redis.Aggregator{{redis.Avg, redis.Sum}},\n}","handlingStrategy":"validation","validationCode":"func validateNRangeSpecs(aggs [][]redis.Aggregator) error {\n    for i, spec := range aggs {\n        for j, a := range spec {\n            if a == redis.Invalid {\n                return fmt.Errorf(\"Invalid aggregator at [%d][%d]\", i, j)\n            }\n        }\n    }\n    return nil\n}","typeGuard":"func isValidAggregator(a redis.Aggregator) bool { return a != redis.Invalid && a <= redis.CountAll }","tryCatchPattern":null,"preventionTips":["Populate inner specs fully with append, not make with partial fill.","Filter redis.Invalid out of each inner spec before the call.","Use named constants for every aggregator assignment."],"tags":["timeseries","nrange","aggregator","validation","invalid-enum"],"analyzedSha":"36d97525cd8076aed67cddf54778e9ea84550929","analyzedAt":"2026-08-06T01:08:27.376Z","schemaVersion":2}