{"record":{"id":"0d5d675f0060715f","repo":"karatelabs/karate","slug":"missing-argument-for-multipart","errorCode":null,"errorMessage":"missing argument for multiPart()","messagePattern":"missing argument for multiPart\\(\\)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/http/HttpRequest.java","lineNumber":675,"sourceCode":"        };\n    }\n\n    private JavaInvokable pathMatches() {\n        return args -> {\n            if (args.length > 0) {\n                return pathMatches(args[0] + \"\");\n            } else {\n                throw new RuntimeException(\"missing argument for pathMatches()\");\n            }\n        };\n    }\n\n    private JavaInvokable multiPart() {\n        return args -> {\n            if (args.length > 0) {\n                return getMultiPart(args[0] + \"\");\n            } else {\n                throw new RuntimeException(\"missing argument for multiPart()\");\n            }\n        };\n    }\n\n    private JavaInvokable file() {\n        return args -> {\n            if (args.length > 0) {\n                return getFile(args[0] + \"\");\n            } else {\n                throw new RuntimeException(\"missing argument for file()\");\n            }\n        };\n    }\n\n    private JavaInvokable files() {\n        return args -> {\n            if (args.length > 0) {\n                return getFiles(args[0] + \"\");","sourceCodeStart":657,"sourceCodeEnd":693,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/http/HttpRequest.java#L657-L693","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nrequest.multiPart(); // throws\n// after\nrequest.multiPart(\"file\");","handlingStrategy":"validation","validationCode":"// script-side guard\nif (!fieldName) throw new Error('multiPart() needs a field name');\nrequest.multiPart(fieldName);","typeGuard":"function hasFieldArg(args) { return Array.isArray(args) && args.length > 0 && args[0] != null; }","tryCatchPattern":null,"preventionTips":["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"],"tags":["http","multipart","missing-argument","dsl"],"backgroundTag":"missing-required-argument","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-16T19:17:19.609Z"}