{"id":"c93ada02b013ddd5","repo":"go-redis/redis","slug":"redis-invalid-bitcount-index","errorCode":null,"errorMessage":"redis: invalid bitcount index","messagePattern":"redis: invalid bitcount index","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"bitmap_commands.go","lineNumber":61,"sourceCode":"\ntype BitCount struct {\n\tStart, End int64\n\tUnit       string // BYTE(default) | BIT\n}\n\nconst BitCountIndexByte string = \"BYTE\"\nconst BitCountIndexBit string = \"BIT\"\n\nfunc (c cmdable) BitCount(ctx context.Context, key string, bitCount *BitCount) *IntCmd {\n\targs := make([]any, 2, 5)\n\targs[0] = \"bitcount\"\n\targs[1] = key\n\tif bitCount != nil {\n\t\targs = append(args, bitCount.Start, bitCount.End)\n\t\tif bitCount.Unit != \"\" {\n\t\t\tif bitCount.Unit != BitCountIndexByte && bitCount.Unit != BitCountIndexBit {\n\t\t\t\tcmd := NewIntCmd(ctx)\n\t\t\t\tcmd.SetErr(errors.New(\"redis: invalid bitcount index\"))\n\t\t\t\treturn cmd\n\t\t\t}\n\t\t\targs = append(args, bitCount.Unit)\n\t\t}\n\t}\n\tcmd := NewIntCmd(ctx, args...)\n\t_ = c(ctx, cmd)\n\treturn cmd\n}\n\nfunc (c cmdable) bitOp(ctx context.Context, op, destKey string, keys ...string) *IntCmd {\n\targs := make([]interface{}, 3+len(keys))\n\targs[0] = \"bitop\"\n\targs[1] = op\n\targs[2] = destKey\n\tfor i, key := range keys {\n\t\targs[3+i] = key\n\t}","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/go-redis/redis/blob/36d97525cd8076aed67cddf54778e9ea84550929/bitmap_commands.go#L43-L79","documentation":"Error \"redis: invalid bitcount index\" thrown in go-redis/redis.","triggerScenarios":"Thrown at bitmap_commands.go:61 when the library encounters an invalid state.","commonSituations":"Clamp computed bit ranges against the known value size before issuing BITCOUNT.","solutions":["Pass bit offsets (not byte offsets) within the key's bit length to BitCount, or omit the range entirely","When using the BYTE unit form, ensure start/end indexes are valid for the string length"],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"36d97525cd8076aed67cddf54778e9ea84550929","analyzedAt":"2026-08-06T01:08:27.376Z","schemaVersion":2}