apache/beam · error · CoderException

Could not read value. Error

Error message

Could not read value. Error: %s

What it means

ThriftCoder.decode instantiates the thrift class reflectively and reads the value from the input stream via the configured protocol. Any exception during read (protocol corruption, instantiation failure, ClassCastException on the cast) is wrapped in a CoderException with this message.

Solutions

  1. Check the cause message after 'Error:' — 'unrecognized protocol' or field-mismatch hints point to writer/reader protocol or IDL mismatch
  2. Ensure the same TProtocolFactory is used on encode and decode sides
  3. Regenerate thrift classes from the current .thrift file and redeploy so reader and writer agree
  4. Verify the input stream is complete and not truncated before decoding

Example fix

// before
ThriftCoder<ThriftRecord> coder = ThriftCoder.of(); // default protocol
ThriftRecord r = coder.decode(inputStream);
// after
ThriftCoder<ThriftRecord> coder =
    ThriftCoder.of(new TCompactProtocol.Factory()); // match writer's protocol
ThriftRecord r = coder.decode(new ByteArrayInputStream(fullPayload));
Defensive patterns

Strategy: try-catch

Validate before calling

if (payload == null || payload.length == 0) { throw new IllegalArgumentException("empty payload for thrift decode"); }

Try / catch

try { return coder.decode(stream); } catch (CoderException e) { LOG.error("thrift decode failed: {}", e.getMessage(), e); return null; /* or dead-letter */ }

Prevention

When it happens

Trigger: Calling decode on bytes that were not written by the matching protocol factory, truncated/corrupted input streams, or a thrift type whose declared constructor throws or whose read() hits a protocol type mismatch.

Common situations: Reading Kafka topics written by producers using a different Thrift protocol (e.g. compact vs binary); schema/IDL drift between writer and reader; deserializing non-Thrift bytes accidentally sent to the same topic.

Understand the failure class

Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/36edc43a925cec45. Report an issue: GitHub.

Appendix: source

Thrown at sdks/java/io/thrift/src/main/java/org/apache/beam/sdk/io/thrift/ThriftCoder.java:102

  /**
   * Decodes a value of type {@code T} from the given input stream using provided {@link
   * ThriftCoder#protocolFactory}. Returns the decoded value.
   *
   * @param inStream stream of input values to be decoded
   * @throws IOException if reading from the {@code InputStream} fails for some reason
   * @throws CoderException if the value could not be decoded for some reason
   * @return {@link TBase} decoded object
   */
  @Override
  public T decode(InputStream inStream) throws CoderException, IOException {
    try {
      TProtocol protocol = protocolFactory.getProtocol(new TIOStreamTransport(inStream));
      TBase<?, ?> value = (TBase<?, ?>) type.getDeclaredConstructor().newInstance();
      value.read(protocol);
      return (T) value;
    } catch (Exception te) {
      throw new CoderException("Could not read value. Error: " + te.getMessage());
    }
  }
}

View on GitHub (pinned to 12126d8942)