{"record":{"id":"c701aa962979b4e2","repo":"xai-org/x-algorithm","slug":"mock-function-expects-either-1-or-3-arguments-but","errorCode":null,"errorMessage":"Mock function expects either 1 or 3 arguments but %d received","messagePattern":"Mock function expects either 1 or 3 arguments but (.+?) received","errorType":"validation","errorClass":"SemanticCheckFailure","httpStatus":null,"severity":"error","filePath":"botmaker/src/java/com/twitter/botmaker/compiler/Compiler.java","lineNumber":1235,"sourceCode":"        ASTNode bodyNode = createASTNodeTree(context, root.getChild(2));\n        context.addMock(funcName, bodyNode);\n      } else if (root.getChildCount() == 4) {\n        for (int i = 1; i < root.getChildCount() - 1; i++) {\n          String funcName = toStringConstant(root.getChild(1));\n          String variableName = getVariableName(root.getChild(2));\n          Type variableType = Type.listOf(Type.OBJECT);\n\n          CompilerScope scope = context.addScope();\n          Parameter parameter = Parameter.open(variableName, variableType);\n          scope.defineVariable(parameter);\n\n          ASTNode bodyNode = createASTNodeTree(context, root.getChild(3));\n          context.removeScope();\n\n          context.addMock(funcName, variableName, bodyNode);\n        }\n      } else {\n        throw new SemanticCheckFailure(\n            String.format(\"Mock function expects either 1 or 3 arguments but %d received\",\n                root.getChildCount() - 1)\n        );\n      }\n    } catch (Exception e) {\n      throw new SemanticCheckFailure(e);\n    }\n\n    return Constant.UNIT;\n  }\n\n  private ASTNode toMockPass(\n      CompilerContext context,\n      String exprText,\n      Tree root) throws SemanticCheckFailure {\n    try {\n      if (root.getChildCount() == 2) {\n        String funcName = toStringConstant(root.getChild(1));","sourceCodeStart":1217,"sourceCodeEnd":1253,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/botmaker/src/java/com/twitter/botmaker/compiler/Compiler.java#L1217-L1253","documentation":"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.","triggerScenarios":"`Mock(\"fn\")` (valid), `Mock(\"fn\", \"x\", expr)` (valid), but `Mock()` or `Mock(\"fn\", expr)` fails with the received count.","commonSituations":"Writing test mocks by hand with the wrong shape, or copy-pasting between Mock and MockPass forms and miscounting arguments.","solutions":["Use either Mock(fnName) or Mock(fnName, varName, bodyExpr) exactly","Remove extra arguments or add the missing variable/body pair"],"exampleFix":"// before\nMock(\"getScore\", ToDouble(0.0))\n// after\nMock(\"getScore\", \"x\", ToDouble(0.0))","handlingStrategy":"validation","validationCode":"int n = mockArgCount;\nif (n != 1 && n != 3) throw new IllegalArgumentException(\"Mock needs 1 or 3 args, got \" + n);","typeGuard":null,"tryCatchPattern":"catch (SemanticCheckFailure e) { if (e.getMessage().contains(\"Mock function expects\")) fixMockShape(); else throw e; }","preventionTips":["Use the canonical Mock(name) / Mock(name, var, body) forms"],"tags":["botmaker","mock","arity","testing"],"backgroundTag":"function-arity-mismatch","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}