{"record":{"id":"9ec7392d4554b97a","repo":"karatelabs/karate","slug":"waitforhttp-needs-a-url-argument","errorCode":null,"errorMessage":"waitForHttp() needs a URL argument","messagePattern":"waitForHttp\\(\\) needs a URL argument","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/core/KarateJsUtils.java","lineNumber":1058,"sourceCode":"                }\n                logger.info(\"*** exited socket wait successfully\");\n                return true;\n            } catch (Exception e) {\n                throw new RuntimeException(\"stop() failed: \" + e.getMessage(), e);\n            }\n        };\n    }\n\n    // ========== Wait Utilities ==========\n\n    /**\n     * karate.waitForHttp(url) - Wait for an HTTP endpoint to become available.\n     * Polls until a successful response (2xx or 3xx) is received.\n     */\n    static JavaInvokable waitForHttp() {\n        return args -> {\n            if (args.length == 0) {\n                throw new RuntimeException(\"waitForHttp() needs a URL argument\");\n            }\n            String url = args[0] + \"\";\n            int timeoutMs = 30000;\n            int pollMs = 250;\n            if (args.length > 1 && args[1] instanceof Map) {\n                @SuppressWarnings(\"unchecked\")\n                Map<String, Object> options = (Map<String, Object>) args[1];\n                if (options.containsKey(\"timeout\")) {\n                    timeoutMs = ((Number) options.get(\"timeout\")).intValue();\n                }\n                if (options.containsKey(\"interval\")) {\n                    pollMs = ((Number) options.get(\"interval\")).intValue();\n                }\n            }\n            long deadline = System.currentTimeMillis() + timeoutMs;\n            java.net.http.HttpClient httpClient = java.net.http.HttpClient.newBuilder()\n                    .connectTimeout(Duration.ofMillis(pollMs))\n                    .build();","sourceCodeStart":1040,"sourceCodeEnd":1076,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/KarateJsUtils.java#L1040-L1076","documentation":"karate.waitForHttp(url) requires a URL as its first argument; calling it with zero arguments throws this RuntimeException immediately. It is a strict arity check protecting against a missing parameter.","triggerScenarios":"Invoking karate.waitForHttp() with no arguments from a JS block or feature file.","commonSituations":"Refactoring a call and dropping the argument; confusing waitForHttp() with a no-arg variant; calling it before defining the URL variable.","solutions":["Pass the URL string as the first argument: karate.waitForHttp('http://localhost:8080/health')","Optionally pass a second Map argument for timeoutMs/pollMs configuration","Define the URL variable before the call"],"exampleFix":"// before\nkarate.waitForHttp();\n// after\nkarate.waitForHttp('http://localhost:8080/health', { timeoutMs: 60000 });","handlingStrategy":"validation","validationCode":"// JS\nif (!url) throw new Error('waitForHttp requires a url');\nkarate.waitForHttp(url);","typeGuard":"// JS\nfunction hasUrl(u) { return typeof u === 'string' && u.length > 0; }","tryCatchPattern":"if (arguments.length === 0) throw new Error('call waitForHttp(url) with a URL string');","preventionTips":["Always pass the URL as the first argument","Keep timeout/poll overrides in the optional second map argument","Define the URL variable before the call site"],"tags":["argument-count","wait","http"],"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"}