xai-org/x-algorithm · error · IllegalArgumentException
Thrift enums are not supported in strato JSON
Error message
Thrift enums are not supported in strato JSON
What it means
The thrift enum serializer (thriftEnumOf for TEnum classes) renders enums as NULL in fingerprint scripts but throws IllegalArgumentException in toStratoJson: thrift enums have no strato JSON encoding here. Any feature/constant typed as a thrift enum fails as soon as it goes through the strato JSON path.
Source
Thrown at botmaker/src/java/com/twitter/botmaker/compiler/Serializer.java:1586
@Override
protected void serialize(TProtocol prot, T value) throws Exception {
prot.writeI32(value.getValue());
}
@Override
protected T deserialize(TProtocol prot) throws Exception {
int v = prot.readI32();
return enumMap.get(v);
}
@Override
protected void toScript(GenScript script, T value) {
script.builder.append("NULL");
}
@Override
protected void toStratoJson(GenScript script, T value) {
throw new IllegalArgumentException("Thrift enums are not supported in strato JSON");
}
};
}
public static <T extends ThriftStruct> Serializer<T> thriftStructOf(Class<T> clazz)
throws SemanticCheckFailure {
try {
ThriftStructCodec codec = ThriftStructCodec.forStructClass(clazz);
return new Serializer<T>() {
@Override
public void computeFingerprint(Hasher hasher, T value) throws TException {
TFingerprintProtocol prot = new TFingerprintProtocol(hasher);
codec.encode(value, prot);
}
@OverrideView on GitHub (pinned to 24c60942c5)
Solutions
- Convert the enum to its integer value or name string before strato JSON serialization and serialize with intOf()/stringOf().
- Model the field as an I32/string in the serving schema and map the enum at the edges.
- Extend toStratoJson in the enum serializer to emit the enum's name/value if the strato format can accept it.
Example fix
// before Serializer.thriftEnumOf(MyEnum.class).genStratoJson(script, MyEnum.A); // throws Thrift enums are not supported in strato JSON // after Serializer.intOf().genStratoJson(script, MyEnum.A.getValue()); // or Serializer.stringOf().genStratoJson(script, MyEnum.A.name());
Defensive patterns
Strategy: fallback
Validate before calling
if (value instanceof TEnum) {
value = ((TEnum) value).getValue(); // serialize as int
} Type guard
static boolean isThriftEnum(Class<?> c) {
return TEnum.class.isAssignableFrom(c);
} Try / catch
catch (IllegalArgumentException e) {
if (e.getMessage().contains("Thrift enums")) {
return serializeAsIntOrName(enumValue);
}
throw e;
} Prevention
- Map thrift enums to int/string at the boundary before serialization.
- Avoid enum-typed fields in strato-served feature schemas.
- Test enum-typed constants through both fingerprint and strato JSON paths.
When it happens
Trigger: Creating a serializer via Serializer.thriftEnumOf(EnumClass.class) and invoking genStratoJson with any enum value (even a valid one).
Common situations: Rule predicates referencing thrift enum constants that are then exported/served via strato; assuming enums serialize like strings; adding an enum-typed field to a strato-served feature.
Related errors
- Pairs are not supported in strato JSON
- Tuples are not supported in strato JSON
- StructTuples are not supported in strato JSON
- Thriftjava objects are not supported in strato JSON
- Thriftscala objects are not supported in strato JSON
AI-assisted analysis of xai-org/x-algorithm@24c60942c5 (2026-08-28).
Data as JSON: /api/errors/cf535360c19da4ab.
Report an issue: GitHub.