xai-org/x-algorithm · error · SemanticCheckFailure
Mock function expects either 1 or 3 arguments but %d receive
Error message
Mock function expects either 1 or 3 arguments but %d received
What it means
The Mock(...) testing construct accepts exactly 1 argument (function name) or 3 arguments (name, variable, body). Any other child count is rejected before the mock is registered.
Source
Thrown at botmaker/src/java/com/twitter/botmaker/compiler/Compiler.java:1235
ASTNode bodyNode = createASTNodeTree(context, root.getChild(2));
context.addMock(funcName, bodyNode);
} else if (root.getChildCount() == 4) {
for (int i = 1; i < root.getChildCount() - 1; i++) {
String funcName = toStringConstant(root.getChild(1));
String variableName = getVariableName(root.getChild(2));
Type variableType = Type.listOf(Type.OBJECT);
CompilerScope scope = context.addScope();
Parameter parameter = Parameter.open(variableName, variableType);
scope.defineVariable(parameter);
ASTNode bodyNode = createASTNodeTree(context, root.getChild(3));
context.removeScope();
context.addMock(funcName, variableName, bodyNode);
}
} else {
throw new SemanticCheckFailure(
String.format("Mock function expects either 1 or 3 arguments but %d received",
root.getChildCount() - 1)
);
}
} catch (Exception e) {
throw new SemanticCheckFailure(e);
}
return Constant.UNIT;
}
private ASTNode toMockPass(
CompilerContext context,
String exprText,
Tree root) throws SemanticCheckFailure {
try {
if (root.getChildCount() == 2) {
String funcName = toStringConstant(root.getChild(1));View on GitHub (pinned to 24c60942c5)
Solutions
- Use either Mock(fnName) or Mock(fnName, varName, bodyExpr) exactly
- Remove extra arguments or add the missing variable/body pair
Example fix
// before
Mock("getScore", ToDouble(0.0))
// after
Mock("getScore", "x", ToDouble(0.0)) Defensive patterns
Strategy: validation
Validate before calling
int n = mockArgCount;
if (n != 1 && n != 3) throw new IllegalArgumentException("Mock needs 1 or 3 args, got " + n); Try / catch
catch (SemanticCheckFailure e) { if (e.getMessage().contains("Mock function expects")) fixMockShape(); else throw e; } Prevention
- Use the canonical Mock(name) / Mock(name, var, body) forms
When it happens
Trigger: `Mock("fn")` (valid), `Mock("fn", "x", expr)` (valid), but `Mock()` or `Mock("fn", expr)` fails with the received count.
Common situations: Writing test mocks by hand with the wrong shape, or copy-pasting between Mock and MockPass forms and miscounting arguments.
Related errors
- MockPass function expects either 1 arguments but %d received
- MockPassAll function expects 1 arguments but %d received
- TestRun function expects 1 arguments but %d received
- The mock for function %s is not defined.
- Derived Feature %s has %d parameters, received %d
AI-assisted analysis of xai-org/x-algorithm@24c60942c5 (2026-08-28).
Data as JSON: /api/errors/c701aa962979b4e2.
Report an issue: GitHub.