prestodb/presto · error · TProtocolException

Can not deserialize the data

Error message

Can not deserialize the data

What it means

ThriftCodecUtils.fromThrift() reads an object of type T from bytes using the given ThriftCodec over a TBinaryProtocol. Any exception during transport write or protocol read is rethrown uniformly as TProtocolException with this message. It is the generic low-level deserialization failure behind higher-level wrappers like GenericThriftCodec.deserialize.

Source

Thrown at presto-thrift-connector-toolkit/src/main/java/com/facebook/presto/thrift/codec/ThriftCodecUtils.java:36

import com.facebook.drift.protocol.TMemoryBuffer;
import com.facebook.drift.protocol.TMemoryBufferWriteOnly;
import com.facebook.drift.protocol.TProtocolException;

public class ThriftCodecUtils
{
    private ThriftCodecUtils() {}

    public static <T> T fromThrift(byte[] bytes, ThriftCodec<T> thriftCodec)
            throws TProtocolException
    {
        try {
            TMemoryBuffer transport = new TMemoryBuffer(bytes.length);
            transport.write(bytes);
            TBinaryProtocol protocol = new TBinaryProtocol(transport);
            return thriftCodec.read(protocol);
        }
        catch (Exception e) {
            throw new TProtocolException("Can not deserialize the data", e);
        }
    }

    public static <T> byte[] toThrift(T value, ThriftCodec<T> thriftCodec)
            throws TProtocolException
    {
        TMemoryBufferWriteOnly transport = new TMemoryBufferWriteOnly(1024);
        TBinaryProtocol protocol = new TBinaryProtocol(transport);
        try {
            thriftCodec.write(value, protocol);
            return transport.getBytes();
        }
        catch (Exception e) {
            throw new TProtocolException("Can not serialize the data", e);
        }
    }
}

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Ensure the bytes were written by ThriftCodecUtils.toThrift() with the same ThriftCodec and TBinaryProtocol
  2. Align Thrift IDL/struct versions between producer and consumer
  3. Validate byte array non-empty and well-formed before the call
  4. Catch TProtocolException and either regenerate the payload or fail with a clear error

Example fix

// before
T value = ThriftCodecUtils.fromThrift(bytes, codec); // TProtocolException on corrupt data
// after
if (bytes == null || bytes.length == 0) {
    throw new IllegalArgumentException("empty payload");
}
try {
    T value = ThriftCodecUtils.fromThrift(bytes, codec);
} catch (TProtocolException e) {
    throw new IOException("incompatible or corrupt Thrift payload", e);
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (bytes == null || bytes.length == 0) {
    throw new IllegalArgumentException("empty Thrift payload");
}

Try / catch

try {
    T value = ThriftCodecUtils.fromThrift(bytes, codec);
} catch (TProtocolException e) {
    throw new IOException("failed to decode Thrift payload (size=" + bytes.length + ")", e);
}

Prevention

When it happens

Trigger: Calling ThriftCodecUtils.fromThrift(bytes, codec) where bytes are empty/corrupt/truncated, not written with TBinaryProtocol, or structurally incompatible with the codec's Thrift type (missing required fields, wrong field types).

Common situations: Version mismatch between services sharing serialized Thrift payloads; hand-crafted or debug-modified byte buffers; network/storage corruption; using the wrong codec class for the bytes.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/cb1e71a82c9ac6ce. Report an issue: GitHub.