karatelabs/karate · error · RuntimeException
missing argument for header()
Error message
missing argument for header()
What it means
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.
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
Example fix
// before
var h = request.header();
// after
var h = request.header('Content-Type'); Defensive patterns
Strategy: type-guard
Validate before calling
if (name == null || name.isEmpty()) throw new IllegalArgumentException("header name required"); Type guard
function requireArg(name, args) { if (args == null || args.length === 0) throw new Error('missing argument for header()'); return name; } Try / catch
try { var h = request.header('X-Token'); } catch (RuntimeException e) { /* fix call site: header name missing */ } Prevention
- 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
When it happens
Trigger: Calling request.header() with no arguments, instead of request.header('X-Token') to read or request.header('X-Token', 'v') to set.
Common situations: Omitted header name while converting from setter-only usage, empty variable interpolated as the name, misunderstanding the overload dispatch.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- missing argument for headerValues()
- missing argument for param()
- missing argument for paramValues()
- missing argument for paramInt()
- missing argument for paramJson()
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/76f0e48cc82817ab.
Report an issue: GitHub.
Appendix: source
Thrown at karate-core/src/main/java/io/karatelabs/http/HttpRequest.java:595
return Json.of(val).value();
} catch (Exception e) {
return val; // return raw string if not valid JSON
}
} else {
throw new RuntimeException("missing argument for paramJson()");
}
};
}
/**
* 1-arg form: {@code request.header('X')} — returns the last value (String) or null.
* 2-arg form: {@code request.header('X', 'v')} — sets the header. {@code null}
* value removes the header. {@code List} value sets all values.
*/
private JavaInvokable header() {
return args -> {
if (args.length == 0) {
throw new RuntimeException("missing argument for header()");
}
String name = args[0] + "";
if (args.length == 1) {
return getHeader(name);
}
putHeaderValue(name, args[1]);
return null;
};
}
@SuppressWarnings("unchecked")
void putHeaderValue(String name, Object value) {
if (value == null) {
removeHeader(name);
return;
}
if (value instanceof List<?> list) {
List<String> strList = new ArrayList<>(list.size());View on GitHub (pinned to a22eb90246)