{"record":{"id":"bfeb2154d052075c","repo":"xai-org/x-algorithm","slug":"structtuple-should-have-at-least-one-field","errorCode":null,"errorMessage":"StructTuple should have at least one field","messagePattern":"StructTuple should have at least one field","errorType":"validation","errorClass":"SemanticCheckFailure","httpStatus":null,"severity":"error","filePath":"botmaker/src/java/com/twitter/botmaker/function/collection/ToStructTuple.java","lineNumber":43,"sourceCode":"    super(exprText, children);\n    this.fieldNames = fieldNames;\n  }\n\n  @Override\n  protected CacheLevel getCacheLevel() {\n    return CacheLevel.Global;\n  }\n\n  @Override\n  protected Object apply(Context<Runtime> context, List<Object> args) throws Exception {\n    return StructTuple.of(fieldNames, args);\n  }\n\n  public static ToStructTuple of(\n      String funcName, ImmutableList<ASTNode> children) throws SemanticCheckFailure {\n\n    if (children.size() == 0) {\n      throw new SemanticCheckFailure(\"StructTuple should have at least one field\");\n    }\n\n    ImmutableList.Builder<String> fieldNamesBuilder = ImmutableList.builder();\n    ImmutableList.Builder<Type> fieldTypesBuilder = ImmutableList.builder();\n    ImmutableList.Builder<ASTNode> childrenBuilder = ImmutableList.builder();\n    for (ASTNode child : children) {\n      if (!(child instanceof ToPair)) {\n        throw new SemanticCheckFailure(\n            String.format(\n                \"StructTuple expects pairs of name and values, but a %s received\", child));\n      }\n\n      fieldNamesBuilder.add(((Constant) child.getChildren().get(0)).getValue().toString());\n      fieldTypesBuilder.add(((ASTNode) child.getChildren().get(1)).getReturnType());\n      childrenBuilder.add((ASTNode) child.getChildren().get(1));\n    }\n\n    ImmutableList<String> fieldNames = fieldNamesBuilder.build();","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/botmaker/src/java/com/twitter/botmaker/function/collection/ToStructTuple.java#L25-L61","documentation":"ToStructTuple() requires at least one field; calling it with zero children throws SemanticCheckFailure during construction. A struct with no fields is not representable, so this is a build-time check.","triggerScenarios":"Writing ToStructTuple() with no arguments, or programmatically building it with an empty children list (e.g. from an empty fields configuration).","commonSituations":"Generating struct definitions from config/JSON where the fields array is empty or missing.","solutions":["Supply at least one name: value pair: ToStructTuple(name: value)","When generating from config, validate the fields list is non-empty before building"],"exampleFix":"// before\nToStructTuple()\n// after\nToStructTuple(id: 1)","handlingStrategy":"validation","validationCode":"// host code before ToStructTuple.of\nif (children.isEmpty()) {\n  throw new IllegalArgumentException(\"StructTuple requires >= 1 field\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always provide at least one name: value field","Validate non-empty field lists when generating from config"],"tags":["botmaker","semantic-check","missing-argument","struct-tuple"],"backgroundTag":"missing-required-argument","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}