{"record":{"id":"f98ebc429b9f7511","repo":"karatelabs/karate","slug":"missing-argument-for-files","errorCode":null,"errorMessage":"missing argument for files()","messagePattern":"missing argument for files\\(\\)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/http/HttpRequest.java","lineNumber":695,"sourceCode":"        };\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.\n     */\n    public HttpResponse proceed(String targetUrl) {\n        if (targetUrl == null) {\n            String host = getHeader(\"Host\");\n            if (host == null) {\n                throw new RuntimeException(\"proceed() needs a target URL or Host header in request\");\n            }\n            targetUrl = \"http://\" + host;\n        }\n        HttpClient client = httpClient != null ? httpClient : new DefaultHttpClientFactory().create();","sourceCodeStart":677,"sourceCodeEnd":713,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/http/HttpRequest.java#L677-L713","documentation":"HttpRequest.files() is a script-facing invokable that takes one argument (a JSON/map of part names to file paths) and forwards it to getFiles(). Called with zero arguments it throws this RuntimeException to fail fast rather than returning null parts.","triggerScenarios":"Calling files() with no arguments, e.g. request.files() instead of request.files({ a: 'a.txt', b: 'b.txt' }); passing an object but through a binding that loses the argument; confusing files() with a no-arg 'list files' getter.","commonSituations":"Bulk multi-file uploads driven by dynamic maps that were never populated; refactors that renamed a variable leaving the call empty; users assuming files() with no args attaches all files in a directory.","solutions":["Pass the JSON map of parts: request.files(read('files.json'))","Ensure the map variable is defined and non-empty before the call","For a single file use file(); for a single form field use multiPart()","If directory-wildcard attachment was intended, build the map yourself (e.g. via karate.forEach over a listing) and pass it"],"exampleFix":"// before\nrequest.files(); // throws\n// after\nrequest.files({ file1: \"a.txt\", file2: \"b.txt\" });","handlingStrategy":"validation","validationCode":"if (filesMap == null || Object.keys(filesMap).length === 0) throw new Error('files() needs a non-empty map of name -> path');\nrequest.files(filesMap);","typeGuard":"function isNonEmptyMap(v) { return v != null && typeof v === 'object' && Object.keys(v).length > 0; }","tryCatchPattern":null,"preventionTips":["Populate and validate the parts map before calling files()","Don't assume files() discovers files implicitly; it needs explicit name->path pairs","Log the map contents when building uploads in dynamic scripts"],"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"}