{"record":{"id":"d9d2bc166ff1c5ef","repo":"prestodb/presto","slug":"can-not-serialize-the-data","errorCode":null,"errorMessage":"Can not serialize the data","messagePattern":"Can not serialize the data","errorType":"exception","errorClass":"TProtocolException","httpStatus":null,"severity":"error","filePath":"presto-thrift-connector-toolkit/src/main/java/com/facebook/presto/thrift/codec/ThriftCodecUtils.java","lineNumber":50,"sourceCode":"            TBinaryProtocol protocol = new TBinaryProtocol(transport);\n            return thriftCodec.read(protocol);\n        }\n        catch (Exception e) {\n            throw new TProtocolException(\"Can not deserialize the data\", e);\n        }\n    }\n\n    public static <T> byte[] toThrift(T value, ThriftCodec<T> thriftCodec)\n            throws TProtocolException\n    {\n        TMemoryBufferWriteOnly transport = new TMemoryBufferWriteOnly(1024);\n        TBinaryProtocol protocol = new TBinaryProtocol(transport);\n        try {\n            thriftCodec.write(value, protocol);\n            return transport.getBytes();\n        }\n        catch (Exception e) {\n            throw new TProtocolException(\"Can not serialize the data\", e);\n        }\n    }\n}\n","sourceCodeStart":32,"sourceCodeEnd":54,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-thrift-connector-toolkit/src/main/java/com/facebook/presto/thrift/codec/ThriftCodecUtils.java#L32-L54","documentation":"ThriftCodecUtils.toThrift() serializes a value of type T using the given ThriftCodec into a TMemoryBuffer via TBinaryProtocol. Any exception thrown by the codec's write() is rethrown as TProtocolException with this message. It indicates the value does not conform to the Thrift schema (missing required fields, invalid types) or the codec itself fails.","triggerScenarios":"Calling ThriftCodecUtils.toThrift(value, codec) with a value that violates the Thrift struct definition (null required field, wrong field type, out-of-range value) or with a codec that throws during write.","commonSituations":"Objects constructed outside normal connector code paths missing required Thrift fields; schema/IDL updates making existing values invalid; passing a value of the wrong generic type to the codec.","solutions":["Ensure the value is fully populated and matches the codec's Thrift struct definition (required fields non-null)","Rebuild the value via the codec's expected domain type constructors/converters","Check for schema drift after Thrift IDL changes and regenerate/redeploy both sides","Catch TProtocolException at the call site and log the value's shape for diagnosis"],"exampleFix":"// before\nbyte[] bytes = ThriftCodecUtils.toThrift(partialValue, codec); // TProtocolException\n// after\nif (partialValue == null || partialValue.getRequiredField() == null) {\n    throw new IllegalArgumentException(\"required Thrift field missing\");\n}\nbyte[] bytes = ThriftCodecUtils.toThrift(partialValue, codec);","handlingStrategy":"validation","validationCode":"if (value == null) {\n    throw new IllegalArgumentException(\"cannot serialize null value\");\n}\n// verify required Thrift fields are populated before write","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate all required Thrift fields are non-null before serialization","Round-trip test codecs in CI","Regenerate codecs after any Thrift IDL change","Ensure generics match: ThriftCodec<T> type parameter equals the value's runtime type"],"tags":["thrift","serialization"],"backgroundTag":"thrift-serialization-failed","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}