prestodb/presto · error · PrestoException

INVALID_ARGUMENTS

INVALID_ARGUMENTS

Error message

Unable to serialize object of type 

What it means

GenericThriftCodec.serialize delegates to the managed ThriftCodec; if serialization fails with TProtocolException it is rethrown as a PrestoException INVALID_ARGUMENTS naming the value's simple class. It indicates the object does not conform to what the Thrift codec expects.

Source

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

        requireNonNull(javaType, "javaType is null");

        if (!(javaType instanceof Class<?>)) {
            throw new IllegalArgumentException("Expected a Class type for javaType, but got: " + javaType.getTypeName());
        }

        Class<?> clazz = (Class<?>) javaType;

        this.thriftCodec = (ThriftCodec<T>) codecManager.getCodec(clazz);
    }

    @Override
    public byte[] serialize(T value)
    {
        try {
            return toThrift(value, thriftCodec);
        }
        catch (TProtocolException e) {
            throw new PrestoException(INVALID_ARGUMENTS, "Unable to serialize object of type " + value.getClass().getSimpleName(), e);
        }
    }

    @Override
    public T deserialize(byte[] bytes)
    {
        try {
            return fromThrift(bytes, thriftCodec);
        }
        catch (TProtocolException e) {
            throw new PrestoException(INVALID_ARGUMENTS, "Unable to deserialize bytes to object of expected type", e);
        }
    }
}

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Validate the object's required Thrift fields are populated before serializing
  2. Check that the codec registered for the class matches the actual value type
  3. Inspect the wrapped TProtocolException cause for the offending field
  4. Fix the value generation code producing invalid field values

Example fix

// before
byte[] bytes = codec.serialize(eventWithNullRequiredField);
// after
if (event.getRequiredField() == null) { throw new IllegalArgumentException("requiredField missing"); }
byte[] bytes = codec.serialize(event);
Defensive patterns

Strategy: validation

Validate before calling

requireNonNull(value); if (!value.getClass().equals(expectedThriftClass)) { throw new IllegalArgumentException("Expected " + expectedThriftClass + " got " + value.getClass()); }

Type guard

boolean isSerializableThriftValue(Object v) { return v != null && codec.supportedType().isInstance(v); }

Try / catch

try { return codec.serialize(value); } catch (PrestoException e) { if (INVALID_ARGUMENTS == e.getErrorCode().getCode()) { log.error("Serialization failed for " + value.getClass() + ", cause: ", e.getCause()); return null; } throw e; }

Prevention

When it happens

Trigger: Calling serialize(value) (directly or via record/writeParquetColumnHive paths) where the value contains fields incompatible with the Thrift schema (null required fields, out-of-range values, wrong types).

Common situations: Sending events with missing required Thrift fields, strings/data exceeding protocol limits, or mismatched codec registration for the value's class.

Related errors


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