{"record":{"id":"76f0e48cc82817ab","repo":"karatelabs/karate","slug":"missing-argument-for-header","errorCode":null,"errorMessage":"missing argument for header()","messagePattern":"missing argument for header\\(\\)","errorType":"validation","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/http/HttpRequest.java","lineNumber":595,"sourceCode":"                    return Json.of(val).value();\n                } catch (Exception e) {\n                    return val; // return raw string if not valid JSON\n                }\n            } else {\n                throw new RuntimeException(\"missing argument for paramJson()\");\n            }\n        };\n    }\n\n    /**\n     * 1-arg form: {@code request.header('X')} — returns the last value (String) or null.\n     * 2-arg form: {@code request.header('X', 'v')} — sets the header. {@code null}\n     * value removes the header. {@code List} value sets all values.\n     */\n    private JavaInvokable header() {\n        return args -> {\n            if (args.length == 0) {\n                throw new RuntimeException(\"missing argument for header()\");\n            }\n            String name = args[0] + \"\";\n            if (args.length == 1) {\n                return getHeader(name);\n            }\n            putHeaderValue(name, args[1]);\n            return null;\n        };\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    void putHeaderValue(String name, Object value) {\n        if (value == null) {\n            removeHeader(name);\n            return;\n        }\n        if (value instanceof List<?> list) {\n            List<String> strList = new ArrayList<>(list.size());","sourceCodeStart":577,"sourceCodeEnd":613,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/http/HttpRequest.java#L577-L613","documentation":"Generic arity guard inside HttpRequest's private header() invokable: it fires when header() is invoked with zero arguments. The 1-arg form reads a header value and the 2-arg form sets/removes one, so a no-arg call has neither a header name nor value to act on and this sentinel RuntimeException is thrown.","triggerScenarios":"Calling request.header() with no arguments, instead of request.header('X-Token') to read or request.header('X-Token', 'v') to set.","commonSituations":"Omitted header name while converting from setter-only usage, empty variable interpolated as the name, misunderstanding the overload dispatch.","solutions":["Pass the header name to read: request.header('Authorization')","Pass name and value to set: request.header('X-Token', 'abc') (null value removes it, List sets all values)","Verify the variable holding the header name is non-empty"],"exampleFix":"// before\nvar h = request.header();\n// after\nvar h = request.header('Content-Type');","handlingStrategy":"type-guard","validationCode":"if (name == null || name.isEmpty()) throw new IllegalArgumentException(\"header name required\");","typeGuard":"function requireArg(name, args) { if (args == null || args.length === 0) throw new Error('missing argument for header()'); return name; }","tryCatchPattern":"try { var h = request.header('X-Token'); } catch (RuntimeException e) { /* fix call site: header name missing */ }","preventionTips":["Always pass at least the header name; header(name) reads, header(name, value) sets, null removes","Validate header-name variables are non-empty","Distinguish 1-arg (get) vs 2-arg (set) forms in templates and generators"],"tags":["http","headers","arguments","api-misuse"],"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"}