xai-org/x-algorithm · error · SemanticCheckFailure

Field %s does not belong to %s

Error message

Field %s does not belong to %s

What it means

A StructTuple field pair names a field that is not in the struct type's fieldNames list, so the value cannot be placed. This is the DSL equivalent of 'no such field' on a struct literal.

Source

Thrown at botmaker/src/java/com/twitter/botmaker/compiler/CompilerUnit.java:284

      }

      @Override
      public ASTNode createASTNode(ImmutableList<ASTNode> children) throws SemanticCheckFailure {

        ImmutableList<String> fieldNames = structTupleType.fieldNames;
        ASTNode[] fieldValues = new ASTNode[fieldNames.size()];

        for (ASTNode child : children) {
          if (!(child instanceof ToPair)) {
            throw new SemanticCheckFailure(
                String.format(
                    "StructTuple expects pairs of name and values, but a %s received", child)
            );
          }

          String fieldName = ((Constant) child.getChildren().get(0)).getValue().toString();
          if (!fieldNames.contains(fieldName)) {
            throw new SemanticCheckFailure(
                String.format("Field %s does not belong to %s", fieldName, toString())
            );
          }
          fieldValues[fieldNames.indexOf(fieldName)] = (ASTNode) child.getChildren().get(1);
        }
        return new ToStructTuple(fn, fieldNames, ImmutableList.copyOf(fieldValues)) {
          @Override
          public Signature getSignature() {
            return signature;
          }
        };
      }
    });
  }
}

View on GitHub (pinned to 24c60942c5)

Solutions

  1. Check the struct definition and correct the field name
  2. Regenerate/refresh thrift/scrooge types if the schema changed recently
  3. Use the correct struct type for the fields being set

Example fix

// before
User(nmae = "bob")
// after
User(name = "bob")
Defensive patterns

Strategy: validation

Validate before calling

if (!structTupleType.fieldNames.contains(fieldName)) throw new IllegalArgumentException("No such field: " + fieldName);

Type guard

boolean isValidField(StructTupleType t, String f) { return t.fieldNames.contains(f); }

Try / catch

catch (SemanticCheckFailure e) { /* compare against current schema field list */ }

Prevention

When it happens

Trigger: Writing MyStruct(wrongField = x) where wrongField is not declared in the struct's schema; using an outdated field name after the thrift struct changed.

Common situations: Thrift schema evolution (renamed/removed fields) with stale expressions; typos in field names; copy-pasting literals between different struct types.

Related errors


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