{"record":{"id":"c54333097c543ec3","repo":"karatelabs/karate","slug":"body-needs-at-least-one-argument","errorCode":null,"errorMessage":"body() needs at least one argument","messagePattern":"body\\(\\) needs at least one argument","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/http/HttpRequestBuilder.java","lineNumber":788,"sourceCode":"            return this;\n        };\n    }\n\n    private JavaInvokable path() {\n        return args -> {\n            for (Object arg : args) {\n                if (arg != null) {\n                    path(arg + \"\");\n                }\n            }\n            return this;\n        };\n    }\n\n    private JavaInvokable body() {\n        return args -> {\n            if (args.length == 0) {\n                throw new RuntimeException(\"body() needs at least one argument\");\n            }\n            body(args[0]);\n            return this;\n        };\n    }\n\n    @Override\n    public Object jsGet(String key) {\n        switch (key) {\n            case \"get\":\n            case \"post\":\n            case \"put\":\n            case \"delete\":\n            case \"head\":\n            case \"options\":\n            case \"trace\":\n            case \"connect\":\n            case \"patch\":","sourceCodeStart":770,"sourceCodeEnd":806,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/http/HttpRequestBuilder.java#L770-L806","documentation":"Arity guard in HttpRequestBuilder's body() JS binding: setting the request body requires at least one argument (the body value, converted downstream). Fires when builder body() is chained with no arguments.","triggerScenarios":"Calling `body()` with zero arguments, e.g. a JS variable holding the payload is undefined: `body(payload)` where payload is undefined collapses to no argument in the JS-to-Java bridge.","commonSituations":"Payload built by a preceding step that failed or returned null/undefined; forgetting to pass the request body in a generated request script.","solutions":["Pass a value explicitly: `body({ a: 1 })`, `body('text')`, `body(xmlNode)`.","Check the variable is defined before the call: `if (payload != null) body(payload)`.","If you truly want no body, simply omit the body() call.","For structured payloads use request/body keywords or pass a string/Map/List which the builder converts.","­"],"exampleFix":"// before\nvar payload = /* may be undefined */;\nbody(payload)\n// after\nif (payload != null) body(payload)","handlingStrategy":"validation","validationCode":"if (payload != null) builder.body(payload);","typeGuard":"function hasBody(v) { return v !== undefined && v !== null; }","tryCatchPattern":"try { builder.body(p); } catch (e) { if (('' + e).includes('at least one argument')) logger.warn('skipping body, payload undefined'); else throw e; }","preventionTips":["Check payload variables for undefined before body()","Omit body() entirely when no body is intended","Build payloads defensively so intermediate steps cannot return undefined"],"tags":["http","request-body","argument-validation"],"backgroundTag":"missing-required-argument","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-16T19:17:19.609Z"}