{"record":{"id":"012399950219ab34","repo":"karatelabs/karate","slug":"missing-argument-for-file","errorCode":null,"errorMessage":"missing argument for file()","messagePattern":"missing argument for file\\(\\)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/http/HttpRequest.java","lineNumber":685,"sourceCode":"        };\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] + \"\");\n            } else {\n                throw new RuntimeException(\"missing argument for files()\");\n            }\n        };\n    }\n\n    /**\n     * Forward this request to a target URL and return the response.\n     * Mirrors {@code karate.proceed()} so JS-file mocks can implement proxy behavior.\n     * If {@code targetUrl} is null, uses the {@code Host} header on this request.","sourceCodeStart":667,"sourceCodeEnd":703,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/http/HttpRequest.java#L667-L703","documentation":"HttpRequest.file() is a script-facing invokable that requires one argument — the name/path of the file part to attach — and forwards it to getFile(). A zero-argument call throws this RuntimeException as an immediate, explicit failure of the DSL contract.","triggerScenarios":"Calling file() with no arguments, e.g. request.file() instead of request.file('data.txt'); the argument variable is undefined; wrong DSL method selected when the author actually wanted multiPart() or files().","commonSituations":"Assembling file uploads where the file path comes from config or a placeholder that failed to substitute; migrating scripts between HTTP DSL versions with different signatures; typos in chained builder expressions.","solutions":["Supply the file part identifier: request.file('path/to/file.txt')","Verify the variable holding the file name/path is non-null before the call","Use files() if you intend to pass a JSON of name->path pairs rather than a single file","Grep the script for other zero-arg calls that should carry arguments"],"exampleFix":"// before\nrequest.file(); // throws\n// after\nrequest.file(\"upload/data.txt\");","handlingStrategy":"validation","validationCode":"if (!filePath) throw new Error('file() needs a file path');\nrequest.file(filePath);","typeGuard":"function hasFileArg(args) { return Array.isArray(args) && args.length > 0 && typeof args[0] === 'string' && args[0].length > 0; }","tryCatchPattern":null,"preventionTips":["Verify the file path variable resolves before the call","Use file() for one file and files() for a map — don't mix","Check placeholder/config substitution actually produced a path"],"tags":["http","file-upload","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"}