{"record":{"id":"026b73d6609b50b7","repo":"apache/cassandra","slug":"unknown-error-code-d","errorCode":null,"errorMessage":"Unknown error code %d","messagePattern":"Unknown error code (.+?)","errorType":"exception","errorClass":"ProtocolException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/exceptions/ExceptionCode.java","lineNumber":77,"sourceCode":"\n    public final int value;\n    private static final Map<Integer, ExceptionCode> valueToCode = new HashMap<>(ExceptionCode.values().length);\n    static\n    {\n        for (ExceptionCode code : ExceptionCode.values())\n            valueToCode.put(code.value, code);\n    }\n\n    ExceptionCode(int value)\n    {\n        this.value = value;\n    }\n\n    public static ExceptionCode fromValue(int value)\n    {\n        ExceptionCode code = valueToCode.get(value);\n        if (code == null)\n            throw new ProtocolException(String.format(\"Unknown error code %d\", value));\n        return code;\n    }\n}\n","sourceCodeStart":59,"sourceCodeEnd":81,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/exceptions/ExceptionCode.java#L59-L81","documentation":"ExceptionCode.fromValue maps numeric protocol error codes to the ExceptionCode enum. Unknown integers (not present in the wire protocol) raise a ProtocolException. This guards the native-protocol error parsing against unrecognized or corrupt values.","triggerScenarios":"Deserializing a native protocol ERROR response whose int code has no ExceptionCode mapping (e.g. a code from a newer/older protocol version the driver doesn't know).","commonSituations":"Driver/server protocol version mismatch; corrupted or malicious frames; writing a custom server sending nonstandard error codes; forward-compatibility issues after upgrades.","solutions":["Upgrade the driver/library to a version that knows the error code","Force a matching protocol version on both client and server (e.g. protocol_version setting)","Log and inspect the raw frame to identify the unexpected code","If intercepting exceptions, fall back to UNKNOWN handling instead of crashing"],"exampleFix":"// before\nExceptionCode code = ExceptionCode.fromValue(0x1234); // ProtocolException\n// after\ntry {\n    ExceptionCode code = ExceptionCode.fromValue(raw);\n} catch (ProtocolException e) {\n    logger.warn(\"Unknown error code \" + raw + \"; treating as UNKNOWN\");\n    code = ExceptionCode.UNKNOWN;\n}","handlingStrategy":"try-catch","validationCode":"// check the code is in the known set before mapping\nboolean known = Arrays.stream(ExceptionCode.values()).anyMatch(c -> c.rawValue == rawValue);","typeGuard":null,"tryCatchPattern":"try {\n    code = ExceptionCode.fromValue(value);\n} catch (ProtocolException e) {\n    logger.warn(\"Unknown error code \" + value + \", falling back to UNKNOWN\");\n    code = ExceptionCode.UNKNOWN;\n}","preventionTips":["Keep client and server protocol versions aligned","Upgrade drivers when upgrading Cassandra to learn new error codes","Never synthesize error codes outside the protocol spec","Sanitize/validate inbound protocol frames"],"tags":["protocol","error-code","deserialization"],"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-17T15:17:12.973Z"}