{"record":{"id":"40d31cda446f3c2b","repo":"xai-org/x-algorithm","slug":"block-body-cannot-be-empty","errorCode":null,"errorMessage":"block body cannot be empty","messagePattern":"block body cannot be empty","errorType":"validation","errorClass":"SemanticCheckFailure","httpStatus":null,"severity":"error","filePath":"botmaker/src/java/com/twitter/botmaker/compiler/Compiler.java","lineNumber":1055,"sourceCode":"        throw new SemanticCheckFailure(\n            String.format(\"Sort expects a collection of %s objects, but gets %s\",\n                Comparable.class.getName(),\n                elementType)\n        );\n      }\n\n      ASTNode result = Sort.toSort(exprText, collectionNode);\n      return result;\n    } else {\n      throw new SemanticCheckFailure(String.format(\n          \"%s node with invalid number of children: %d\", root.getText(), root.getChildCount()));\n    }\n  }\n\n  private ASTNode toBlock(CompilerContext context, Tree root)\n      throws ParseFailure, SemanticCheckFailure {\n    if (root.getChildCount() == 0) {\n      throw new SemanticCheckFailure(\"block body cannot be empty\");\n    }\n\n    CompilerScope currentScope = context.addScope();\n    ImmutableList.Builder<ASTNode> childrenBuilder = ImmutableList.builder();\n    for (int i = 0; i < root.getChildCount(); i++) {\n      childrenBuilder.add(createASTNodeTree(context, root.getChild(i)));\n    }\n    ImmutableList.Builder<Pair<String, Type>> variableListBuilder = ImmutableList.builder();\n    for (Map.Entry<String, Parameter> entry : currentScope.getVariables().entrySet()) {\n      variableListBuilder.add(Pair.of(entry.getKey(), entry.getValue().getReturnType()));\n    }\n    context.removeScope();\n    return new Block(\n        root.getText(),\n        childrenBuilder.build(),\n        variableListBuilder.build()\n    );\n  }","sourceCodeStart":1037,"sourceCodeEnd":1073,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/botmaker/src/java/com/twitter/botmaker/compiler/Compiler.java#L1037-L1073","documentation":"A block expression `begin ... end` (or equivalent) must contain at least one statement; toBlock rejects empty blocks because there is no value to yield.","triggerScenarios":"Writing a block whose body is empty, usually because a template stripped out all statements or a conditional block was left blank after editing.","commonSituations":"Rule templates that omit optional sections, refactoring that deletes the last statement in a block, or code generation emitting `begin end` for empty inputs.","solutions":["Add at least one expression/statement to the block","If the block may legitimately be empty, guard generation so the whole block is omitted","Make the block end with the value you want it to evaluate to"],"exampleFix":"// before\nbegin end\n// after\nbegin 0L end","handlingStrategy":"validation","validationCode":"if (blockStatements.isEmpty()) omitBlock(); // or insert a default value expression","typeGuard":null,"tryCatchPattern":"catch (SemanticCheckFailure e) { if (\"block body cannot be empty\".equals(e.getMessage())) insertDefaultValue(); else throw e; }","preventionTips":["Never generate begin/end blocks with empty bodies","End blocks with an explicit result expression"],"tags":["botmaker","block","empty-body"],"backgroundTag":"empty-block","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}