{"record":{"id":"fb11154db5a45445","repo":"karatelabs/karate","slug":"param-needs-two-arguments","errorCode":null,"errorMessage":"param() needs two arguments","messagePattern":"param\\(\\) needs two arguments","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/http/HttpRequestBuilder.java","lineNumber":730,"sourceCode":"            }\n            return invoke();\n        };\n    }\n\n    private JavaInvokable header() {\n        return args -> {\n            if (args.length < 2) {\n                throw new RuntimeException(\"header() needs two arguments\");\n            }\n            header(args[0] + \"\", args[1] + \"\");\n            return this;\n        };\n    }\n\n    private JavaInvokable param() {\n        return args -> {\n            if (args.length < 2) {\n                throw new RuntimeException(\"param() needs two arguments\");\n            }\n            param(args[0] + \"\", args[1] + \"\");\n            return this;\n        };\n    }\n\n    /**\n     * The JS-facing plural forms of {@link #param} and {@link #header}. The Java\n     * {@link #params(Map)} takes a {@code Map<String, List<String>>} and replaces what was\n     * there, which is awkward to satisfy from JS - these accumulate and accept a scalar or a\n     * list per key, matching the {@code params} and {@code headers} keywords.\n     */\n    private JavaInvokable params() {\n        return args -> {\n            if (args.length == 0 || !(args[0] instanceof Map<?, ?> map)) {\n                throw new RuntimeException(\"params() needs a map argument\");\n            }\n            map.forEach((k, v) -> {","sourceCodeStart":712,"sourceCodeEnd":748,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/http/HttpRequestBuilder.java#L712-L748","documentation":"HttpRequestBuilder exposes param() to scripts as a two-argument invokable (name, value) that adds a URL query parameter. Called with fewer than two arguments it throws this RuntimeException, failing fast instead of adding a malformed parameter.","triggerScenarios":"Calling param() or param('page') with a single argument from a script; dynamic query-string construction where the value variable is undefined; confusing param(name, value) with param-getter methods elsewhere in the API.","commonSituations":"Building paginated/filtered requests where params come from a map or user input and some entries are missing; templated scripts where a placeholder failed to substitute; learners assuming param() with one arg sets a flag-style parameter.","solutions":["Pass both name and value: builder.param('page', '2')","Build params from a map using the map-accepting overload or loop with explicit key/value","Skip empty values in your loop instead of calling param() with them","For flag-style parameters, pass an empty-string value explicitly: param('verbose', '')"],"exampleFix":"// before\nbuilder.param(\"page\"); // throws\n// after\nbuilder.param(\"page\", \"2\");","handlingStrategy":"validation","validationCode":"if (paramValue == null) throw new Error('query param ' + paramName + ' has no value');\nbuilder.param(paramName, paramValue + '');","typeGuard":"function paramArgsOk(name, value) { return name != null && value != null; }","tryCatchPattern":null,"preventionTips":["Always pass (name, value) to param(); flag-style params should use an empty string value","Validate dynamic param maps before iterating","Convert values to strings explicitly so undefined doesn't drop the argument"],"tags":["http","query-params","missing-argument","dsl"],"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"}