karatelabs/karate · error · RuntimeException
missing argument for headerValues()
Error message
missing argument for headerValues()
What it means
Generic arity guard inside HttpResponse's private headerValues() invokable (reached via getMember): it fires when headerValues() is invoked on a response with zero arguments. The input at fault is the missing header name; with an argument it returns all values for that response header, and without one this sentinel RuntimeException is thrown.
Solutions
- Pass the header name: `response.headerValues('Set-Cookie')`.
- Check the name variable is defined/non-null before calling.
- For a single value use `response.header(name)` instead.
-
Example fix
// before
response.headerValues()
// after
var cookies = response.headerValues('Set-Cookie') Defensive patterns
Strategy: validation
Validate before calling
if (name != null) var vals = response.headerValues(name);
Type guard
function hasHeaderName(v) { return typeof v === 'string' && v.length > 0; } Try / catch
try { return response.headerValues(name); } catch (e) { if (('' + e).includes('missing argument')) return []; throw e; } Prevention
- Pass a non-empty header name string
- Default to response.header(name) when only one value is needed
- Verify header names against the actual response headers
When it happens
Trigger: `response.headerValues()` with zero args, typically when the name variable is undefined or the argument was dropped.
Common situations: Multi-value headers like Set-Cookie where a developer explored the API without the name; refactoring that lost the argument.
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 header()
- missing argument for header()
- missing argument for headerValues()
- header() needs two arguments
- headers() needs a map argument
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/fb115389f41bb7b9.
Report an issue: GitHub.
Appendix: source
Thrown at karate-core/src/main/java/io/karatelabs/http/HttpResponse.java:405
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;
};
}
private JavaInvokable headerValues() {
return args -> {
if (args.length > 0) {
return getHeaderValues(args[0] + "");
} else {
throw new RuntimeException("missing argument for headerValues()");
}
};
}
/**
* Coerce a JS value into the header storage shape ({@code List<String>}).
* Shared by {@code header(name, value)} and the {@code headers[name] = v}
* bracket-set path.
*/
@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());
for (Object o : list) {View on GitHub (pinned to a22eb90246)