{"record":{"id":"c359dfe219b4462b","repo":"vitessio/vitess","slug":"unexpected-bit-operation","errorCode":null,"errorMessage":"unexpected bit operation","messagePattern":"unexpected bit operation","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtgate/evalengine/expr_bit.go","lineNumber":243,"sourceCode":"\t\treturn newEvalUint64(op.numeric(uint64(lu.i), uint64(ru.i))), nil\n\n\tcase opBitShift:\n\t\t/*\n\t\t\tThe result type depends on whether the bit argument is evaluated as a binary string or number:\n\t\t\tBinary-string evaluation occurs when the bit argument has a binary string type, and is not a hexadecimal\n\t\t\tliteral, bit literal, or NULL literal. Numeric evaluation occurs otherwise, with argument conversion to an\n\t\t\tunsigned 64-bit integer as necessary.\n\t\t*/\n\t\tif l, ok := l.(*evalBytes); ok && l.isBinary() && !l.isHexOrBitLiteral() {\n\t\t\tru := evalToInt64(r)\n\t\t\treturn newEvalBinary(op.binary(l.bytes, uint64(ru.i))), nil\n\t\t}\n\t\tlu := evalToInt64(l)\n\t\tru := evalToInt64(r)\n\t\treturn newEvalUint64(op.numeric(uint64(lu.i), uint64(ru.i))), nil\n\n\tdefault:\n\t\tpanic(\"unexpected bit operation\")\n\t}\n}\n\nfunc (expr *BitwiseExpr) compileBinary(c *compiler, asm_ins_bb, asm_ins_uu func()) (ctype, error) {\n\tlt, err := expr.Left.compile(c)\n\tif err != nil {\n\t\treturn ctype{}, err\n\t}\n\n\tskip1 := c.compileNullCheck1(lt)\n\n\trt, err := expr.Right.compile(c)\n\tif err != nil {\n\t\treturn ctype{}, err\n\t}\n\n\tskip2 := c.compileNullCheck1r(rt)\n","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtgate/evalengine/expr_bit.go#L225-L261","documentation":"Panic in the runtime evaluation of bitwise expressions (`BitwiseExpr.eval`). The operator enum is expected to contain only opBitBinary and opBitShift variants; any other value reaches `default: panic(\"unexpected bit operation\")`. It indicates a BitwiseExpr was constructed with an operator the evaluator does not know.","triggerScenarios":"Evaluating a bitwise expression (&, |, ^, <<, >>) whose `bit.Op` is neither opBitBinary nor opBitShift — e.g. a new bitwise operator added to the parser but not to the evaluator's switch.","commonSituations":"Development-time issue after adding new bitwise operators or refactoring the op enum; on a released binary it would crash vtgate on a specific query.","solutions":["Add the missing operator case to BitwiseExpr.eval with its binary/numeric implementation","Ensure the parser cannot produce BitwiseExpr with unknown operators","Return a vterrors internal error instead of panicking","Upgrade to a Vitess release containing the missing operator support"],"exampleFix":"// before\ndefault:\n    panic(\"unexpected bit operation\")\n// after\ndefault:\n    return nil, vterrors.Errorf(vtrpcpb.Code_INTERNAL, \"unexpected bit operation %v\", bit.Op)","handlingStrategy":"type-guard","validationCode":"switch bit.Op.(type) {\ncase opBitBinary, opBitShift:\n    // ok\ndefault:\n    return vterrors.Errorf(vtrpcpb.Code_INTERNAL, \"unsupported bit operator %v\", bit.Op)\n}","typeGuard":"func isKnownBitOp(op BitOp) bool {\n    switch op.(type) {\n    case opBitBinary, opBitShift:\n        return true\n    }\n    return false\n}","tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        err = vterrors.Errorf(vtrpcpb.Code_INTERNAL, \"bitwise eval panic: %v\", r)\n    }\n}()","preventionTips":["Add evaluator support in the same change that introduces a new bitwise operator","Keep the op enum small and cover eval in unit tests for every operator","Prefer returning vterrors internal errors over panic in eval paths"],"tags":["go","panic","bitwise","evalengine","invariant"],"backgroundTag":"unreachable-invariant-panic","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}