xai-org/x-algorithm · error · SemanticCheckFailure

%s cannnot be converted to %s. field type %s mismatch.

Error message

%s cannnot be converted to %s. field type %s mismatch.

What it means

During StructTuple conversion, every shared field name must have an identical field Type on both sides. If fieldTypes differ for the same field index, the converter aborts with SemanticCheckFailure.

Source

Thrown at botmaker/src/java/com/twitter/botmaker/compiler/types/StructTupleType.java:99

    return ofStructTuple(fieldNames, ImmutableList.copyOf(inferredTypeParams));
  }

  public Function<StructTuple, StructTuple> converter(
      StructTupleType structTupleType) throws SemanticCheckFailure {
    int[] indexMap = new int[structTupleType.fieldNames.size()];
    for (int i = 0; i < structTupleType.fieldNames.size(); i++) {
      int fi = fieldNames.indexOf(structTupleType.fieldNames.get(i));
      if (fi < 0) {
        throw new SemanticCheckFailure(
            String.format("%s cannnot be converted to %s. missing field %s.",
                this,
                structTupleType,
                structTupleType.fieldNames.get(i))
        );
      }
      if (!fieldTypes.get(fi).equals(structTupleType.fieldTypes.get(i))) {
        throw new SemanticCheckFailure(
            String.format("%s cannnot be converted to %s. field type %s mismatch.",
                this,
                structTupleType,
                structTupleType.fieldNames.get(i))
        );
      }
      indexMap[i] = fi;
    }

    return Function.func((StructTuple t) -> {
      List<Object> fieldValues = Lists.newArrayListWithCapacity(indexMap.length);
      for (int i = 0; i < indexMap.length; i++) {
        fieldValues.add(t.get(indexMap[i]));
      }
      return StructTuple.of(
          structTupleType.fieldNames,
          fieldValues
      );

View on GitHub (pinned to 24c60942c5)

Solutions

  1. Align the field types by regenerating both tuple classes from the same schema
  2. Add an explicit cast/projection in the rule so both sides agree on type
  3. Verify types with getFieldType on both sides before converting

Example fix

// before
srcType.converter(dstType); // field 'id' is LONG in src, INT in dst
// after
// regenerate dst from the same schema so 'id' is LONG in both, then:
srcType.converter(dstType);
Defensive patterns

Strategy: validation

Validate before calling

for (String f : dst.getFieldNames()) {
  if (!src.getFieldType(f).equals(dst.getFieldType(f))) {
    throw new IllegalArgumentException("type mismatch on " + f);
  }
}

Try / catch

catch SemanticCheckFailure; surface field name and both types to guide schema realignment

Prevention

When it happens

Trigger: converter(target) where a field exists in both StructTupleTypes but with different Types, e.g. LONG vs INT, or a nested struct type regenerated with different parameters.

Common situations: Thrift schema evolution changing a field's type (int32 -> int64), mixed thrift class versions across services, hand-edited StructTuple definitions.

Related errors


AI-assisted analysis of xai-org/x-algorithm@24c60942c5 (2026-08-28). Data as JSON: /api/errors/9a5779722f70ea33. Report an issue: GitHub.