xai-org/x-algorithm · error · SemanticCheckFailure
block body cannot be empty
Error message
block body cannot be empty
What it means
A block expression `begin ... end` (or equivalent) must contain at least one statement; toBlock rejects empty blocks because there is no value to yield.
Source
Thrown at botmaker/src/java/com/twitter/botmaker/compiler/Compiler.java:1055
throw new SemanticCheckFailure(
String.format("Sort expects a collection of %s objects, but gets %s",
Comparable.class.getName(),
elementType)
);
}
ASTNode result = Sort.toSort(exprText, collectionNode);
return result;
} else {
throw new SemanticCheckFailure(String.format(
"%s node with invalid number of children: %d", root.getText(), root.getChildCount()));
}
}
private ASTNode toBlock(CompilerContext context, Tree root)
throws ParseFailure, SemanticCheckFailure {
if (root.getChildCount() == 0) {
throw new SemanticCheckFailure("block body cannot be empty");
}
CompilerScope currentScope = context.addScope();
ImmutableList.Builder<ASTNode> childrenBuilder = ImmutableList.builder();
for (int i = 0; i < root.getChildCount(); i++) {
childrenBuilder.add(createASTNodeTree(context, root.getChild(i)));
}
ImmutableList.Builder<Pair<String, Type>> variableListBuilder = ImmutableList.builder();
for (Map.Entry<String, Parameter> entry : currentScope.getVariables().entrySet()) {
variableListBuilder.add(Pair.of(entry.getKey(), entry.getValue().getReturnType()));
}
context.removeScope();
return new Block(
root.getText(),
childrenBuilder.build(),
variableListBuilder.build()
);
}View on GitHub (pinned to 24c60942c5)
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
Example fix
// before begin end // after begin 0L end
Defensive patterns
Strategy: validation
Validate before calling
if (blockStatements.isEmpty()) omitBlock(); // or insert a default value expression
Try / catch
catch (SemanticCheckFailure e) { if ("block body cannot be empty".equals(e.getMessage())) insertDefaultValue(); else throw e; } Prevention
- Never generate begin/end blocks with empty bodies
- End blocks with an explicit result expression
When it happens
Trigger: Writing a block whose body is empty, usually because a template stripped out all statements or a conditional block was left blank after editing.
Common situations: Rule templates that omit optional sections, refactoring that deletes the last statement in a block, or code generation emitting `begin end` for empty inputs.
Related errors
- unrecognized function name:
- class to be imported has to be either a TBase or ThriftStruc
- cannot find class %s
- function passed to Foldl() returns %s but seed value is a %s
- Foldl1 is expected to return %s but passed function returns
AI-assisted analysis of xai-org/x-algorithm@24c60942c5 (2026-08-28).
Data as JSON: /api/errors/40d31cda446f3c2b.
Report an issue: GitHub.