{"record":{"id":"10af1b06249246c1","repo":"apache/cassandra","slug":"unknown-code-d-for-a-consistency-level","errorCode":null,"errorMessage":"Unknown code %d for a consistency level","messagePattern":"Unknown code (.+?) for a consistency level","errorType":"exception","errorClass":"ProtocolException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/ConsistencyLevel.java","lineNumber":87,"sourceCode":"            codeIdx[cl.code] = cl;\n        }\n    }\n\n    ConsistencyLevel(int code)\n    {\n        this(code, false);\n    }\n\n    ConsistencyLevel(int code, boolean isDCLocal)\n    {\n        this.code = code;\n        this.isDCLocal = isDCLocal;\n    }\n\n    public static ConsistencyLevel fromCode(int code)\n    {\n        if (code < 0 || code >= codeIdx.length)\n            throw new ProtocolException(String.format(\"Unknown code %d for a consistency level\", code));\n        return codeIdx[code];\n    }\n\n    public static ConsistencyLevel fromString(String str)\n    {\n        return valueOf(toUpperCaseLocalized(str));\n    }\n\n    public static int quorumFor(AbstractReplicationStrategy replicationStrategy)\n    {\n        return (replicationStrategy.getReplicationFactor().allReplicas / 2) + 1;\n    }\n\n    public static int localQuorumFor(AbstractReplicationStrategy replicationStrategy, String dc)\n    {\n        return (replicationStrategy instanceof NetworkTopologyStrategy)\n             ? (((NetworkTopologyStrategy) replicationStrategy).getReplicationFactor(dc).allReplicas / 2) + 1\n             : quorumFor(replicationStrategy);","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/ConsistencyLevel.java#L69-L105","documentation":"Thrown by ConsistencyLevel.fromCode when a wire-protocol consistency level code is outside the valid range [0, codeIdx.length). The native protocol encodes consistency levels as shorts and this maps them back to enum values. It means the client sent an unrecognized consistency code.","triggerScenarios":"A CQL native protocol request whose consistency-level field is negative or exceeds the highest defined enum code, e.g. a driver bug or a hand-rolled protocol client.","commonSituations":"Custom or old driver versions speaking a mismatched protocol version; proxy/middleware rewriting frames incorrectly; fuzzing or malformed client traffic.","solutions":["Upgrade the client driver to a version compatible with the server's protocol version.","Check for intermediaries (proxies, LBs with protocol awareness) mangling frames; disable or upgrade them.","Pin a supported protocol version in the driver config (e.g. protocolVersion: v4) to avoid negotiation issues.","Inspect server logs for the offending client and reproduce with a known-good driver."],"exampleFix":"// before: driver negotiating an unsupported protocol version\nCluster.builder().addContactPoint(host).build();\n// after\nCluster.builder().addContactPoint(host)\n       .withProtocolVersion(ProtocolVersion.V4)\n       .build();","handlingStrategy":"validation","validationCode":"// Java driver client-side guard\nif (code < 0 || code > 13) throw new IllegalArgumentException(\"invalid consistency code \" + code);","typeGuard":null,"tryCatchPattern":"catch (ProtocolException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"Unknown code\")) {\n        // downgrade protocol version or upgrade driver\n        reconnectWithLowerProtocolVersion();\n    } else throw e;\n}","preventionTips":["Use an officially supported driver version matching your server release.","Pin the protocol version explicitly instead of letting negotiation drift.","Avoid hand-rolling native protocol frames.","Log and review clients sending malformed frames."],"tags":["cassandra","native-protocol","consistency-level","wire-format"],"backgroundTag":"invalid-enum-value","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}