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
- Pass the form field name: request.multiPart('file') (plus the value/path via file()/files() as designed)
- Check the script binding — ensure the variable holding the field name is defined and not undefined at call time
- If a zero-arg invocation was intended, use the correct API (e.g. a builder method that lists existing parts) instead of multiPart()
- 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
- Always pass the form-field name to multiPart()
- Keep field names in named variables and validate them before building the request
- When migrating scripts, re-check every multiPart call site for its argument
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
- missing argument for file()
- missing argument for files()
- cache() requires (key, fn)
- header() needs two arguments
- param() needs two arguments
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)