karatelabs/karate · error · RuntimeException

missing argument for headerValues()

Error message

missing argument for headerValues()

What it means

Generic arity guard inside HttpRequest's private headerValues() invokable: it fires when headerValues() is invoked with zero arguments. The input at fault is the missing header name whose list of values should be returned, so the lookup cannot proceed and this sentinel RuntimeException is thrown.

Solutions

  1. Pass the header name: request.headerValues('Set-Cookie')
  2. Ensure the name variable is populated before the call
  3. Use header(name) for the single last-value form when only one value is needed

Example fix

// before
var vs = request.headerValues();
// after
var vs = request.headerValues('Accept');
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 headerValues()'); return name; }

Try / catch

try { var vs = request.headerValues('Accept'); } catch (RuntimeException e) { /* fix call site: header name missing */ }

Prevention

When it happens

Trigger: Calling request.headerValues() with no arguments instead of request.headerValues('Accept').

Common situations: Omitted name during edits, empty interpolated variable, expecting a no-arg listing of all headers.

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


AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12). Data as JSON: /api/errors/3dce5fa6191feda7. Report an issue: GitHub.

Appendix: source

Thrown at karate-core/src/main/java/io/karatelabs/http/HttpRequest.java:655

                removeHeader(key);
            }

            @Override
            public Map<String, Object> toMap() {
                if (headers == null) {
                    return Collections.emptyMap();
                }
                return new LinkedHashMap<>(headers);
            }
        };
    }

    private JavaInvokable headerValues() {
        return args -> {
            if (args.length > 0) {
                return getHeaderValues(args[0] + "");
            } else {
                throw new RuntimeException("missing argument for headerValues()");
            }
        };
    }

    private JavaInvokable pathMatches() {
        return args -> {
            if (args.length > 0) {
                return pathMatches(args[0] + "");
            } else {
                throw new RuntimeException("missing argument for pathMatches()");
            }
        };
    }

    private JavaInvokable multiPart() {
        return args -> {
            if (args.length > 0) {
                return getMultiPart(args[0] + "");

View on GitHub (pinned to a22eb90246)