karatelabs/karate · error · RuntimeException

missing argument for multiPart()

Error message

missing argument for multiPart()

What it means

HttpRequest.multiPart() is exposed to scripts as an invokable DSL method that expects exactly one argument (the form field name) which it forwards to getMultiPart(). When it is called with zero arguments the library throws this RuntimeException instead of failing later with a confusing null/ClassCastException deep in the multipart building code.

Solutions

  1. Pass the form field name: request.multiPart('file') (plus the value/path via file()/files() as designed)
  2. Check the script binding — ensure the variable holding the field name is defined and not undefined at call time
  3. If a zero-arg invocation was intended, use the correct API (e.g. a builder method that lists existing parts) instead of multiPart()
  4. Inspect the call site for dynamic dispatch (reflection / JS eval) that may be dropping arguments

Example fix

// before
request.multiPart(); // throws
// after
request.multiPart("file");
Defensive patterns

Strategy: validation

Validate before calling

// script-side guard
if (!fieldName) throw new Error('multiPart() needs a field name');
request.multiPart(fieldName);

Type guard

function hasFieldArg(args) { return Array.isArray(args) && args.length > 0 && args[0] != null; }

Prevention

When it happens

Trigger: Calling multiPart() with no arguments from a script/JS binding, e.g. request.multiPart() instead of request.multiPart('field'); typically a typo, a refactor that dropped the parameter, or a wrong reference to another overloaded multiPart variant that takes no args.

Common situations: Building multipart/form-data uploads by hand where a field name variable is empty or undefined and JS silently coerces the call to a zero-arg invocation; porting older Karate scripts to the new HttpRequest DSL; copy-paste of header()/param() chains where the author forgot multiPart needs a name.

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/0d5d675f0060715f. Report an issue: GitHub.

Appendix: source

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

        };
    }

    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] + "");
            } else {
                throw new RuntimeException("missing argument for multiPart()");
            }
        };
    }

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

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

View on GitHub (pinned to a22eb90246)