{"id":"440a405f3501ac15","repo":"go-redis/redis","slug":"redis-empty-timeseries-aggregator-spec-at-index","errorCode":null,"errorMessage":"redis: empty timeseries aggregator spec at index %d","messagePattern":"redis: empty timeseries aggregator spec at index (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"timeseries_commands.go","lineNumber":1382,"sourceCode":"\t}\n\treturn &TSNRangePivotRowSliceCmd{\n\t\tbaseCmd: cmd.cloneBaseCmd(),\n\t\tval:     val,\n\t}\n}\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.","sourceCodeStart":1364,"sourceCodeEnd":1400,"githubUrl":"https://github.com/go-redis/redis/blob/36d97525cd8076aed67cddf54778e9ea84550929/timeseries_commands.go#L1364-L1400","documentation":"Returned by buildNRangeAggregationArgs when one of the per-key aggregator specs in the Aggregators [][]Aggregator slice is an empty slice (len == 0). Each key that is present in the aggregators list must declare at least one aggregator.","triggerScenarios":"Calling TSNRangeWithArgs/TSNRevRangeWithArgs where Aggregators[i] is []Aggregator{} for some key i (allocated but never populated).","commonSituations":"Initialising the outer slice to the right length with make but forgetting to fill an inner element, or conditionally appending specs where one branch appends nothing.","solutions":["Ensure every Aggregators[i] contains at least one valid aggregator.","Build specs with append so empty entries are never created: for _, k := range keys { specs = append(specs, []redis.Aggregator{redis.Avg}) }.","Validate each inner slice is non-empty before the call."],"exampleFix":"// before\nopts := & redis.TSNRangeOptions{\n    Aggregators: [][]redis.Aggregator{{redis.Avg}, {}},\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        if len(spec) == 0 {\n            return fmt.Errorf(\"empty aggregator spec at index %d\", i)\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Build inner specs with append so empty slices are never created.","Validate each inner slice is non-empty before the call.","Avoid make([][]redis.Aggregator, n) without populating every element."],"tags":["timeseries","nrange","aggregator","validation","empty-slice"],"analyzedSha":"36d97525cd8076aed67cddf54778e9ea84550929","analyzedAt":"2026-08-06T01:08:27.376Z","schemaVersion":2}