{"record":{"id":"17edcf6d85e062ac","repo":"karatelabs/karate","slug":"header-needs-two-arguments","errorCode":null,"errorMessage":"header() needs two arguments","messagePattern":"header\\(\\) needs two arguments","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/http/HttpRequestBuilder.java","lineNumber":720,"sourceCode":"        return sb.toString();\n    }\n\n    private JavaInvokable method() {\n        return args -> {\n            if (args.length > 1) {\n                body = args[1];\n            }\n            if (args.length > 0) {\n                method = args[0] + \"\";\n            }\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","sourceCodeStart":702,"sourceCodeEnd":738,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/http/HttpRequestBuilder.java#L702-L738","documentation":"HttpRequestBuilder exposes header() to scripts as a two-argument invokable (name, value) that delegates to header(String,String). A call with fewer than two arguments throws this RuntimeException because a header without a name+value pair is meaningless.","triggerScenarios":"Calling header() or header('Authorization') with only one argument from a script binding; undefined/empty variables collapsing the argument count; mixing up header(name, value) with the header-getter overloads on other classes.","commonSituations":"Chained request building in JS where a values array was empty; dynamic header loops that skip empty values but still call header() once; porting code between Karate's DSL and raw Java header APIs with different signatures.","solutions":["Pass both name and value: builder.header('Authorization', 'Bearer ' + token)","Check argument-producing expressions (splits, destructuring) aren't yielding a single element","If the value is optional, conditionally call header() only when the value exists","For multiple headers pass a map via the appropriate overload instead of repeated partial calls"],"exampleFix":"// before\nbuilder.header(\"Authorization\"); // throws\n// after\nbuilder.header(\"Authorization\", \"Bearer \" + token);","handlingStrategy":"validation","validationCode":"if (headerValue == null) throw new Error('header ' + headerName + ' has no value; skip or set it');\nbuilder.header(headerName, headerValue);","typeGuard":"function headerArgsOk(name, value) { return name != null && value != null; }","tryCatchPattern":null,"preventionTips":["Always pass (name, value) pairs to header()","Skip empty header values conditionally instead of calling header() with one arg","Use the map overload for multiple headers to avoid partial calls"],"tags":["http","headers","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"}