{"record":{"id":"7488da8efc49f989","repo":"karatelabs/karate","slug":"waitforport-needs-host-and-port-arguments","errorCode":null,"errorMessage":"waitForPort() needs host and port arguments","messagePattern":"waitForPort\\(\\) needs host and port arguments","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/core/KarateJsUtils.java","lineNumber":1110,"sourceCode":"                try {\n                    Thread.sleep(pollMs);\n                } catch (InterruptedException e) {\n                    Thread.currentThread().interrupt();\n                    return false;\n                }\n            }\n            throw new RuntimeException(\"HTTP endpoint not available: \" + url);\n        };\n    }\n\n    /**\n     * karate.waitForPort(host, port) - Wait for a TCP port to become available.\n     * Polls until a TCP connection can be established.\n     */\n    static JavaInvokable waitForPort() {\n        return args -> {\n            if (args.length < 2) {\n                throw new RuntimeException(\"waitForPort() needs host and port arguments\");\n            }\n            String host = args[0] + \"\";\n            int port;\n            if (args[1] instanceof Number) {\n                port = ((Number) args[1]).intValue();\n            } else {\n                port = Integer.parseInt(args[1].toString());\n            }\n            int timeoutMs = 30000;\n            int pollMs = 250;\n            if (args.length > 2 && args[2] instanceof Number) {\n                timeoutMs = ((Number) args[2]).intValue();\n            }\n            if (args.length > 3 && args[3] instanceof Number) {\n                pollMs = ((Number) args[3]).intValue();\n            }\n            long deadline = System.currentTimeMillis() + timeoutMs;\n            while (System.currentTimeMillis() < deadline) {","sourceCodeStart":1092,"sourceCodeEnd":1128,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/KarateJsUtils.java#L1092-L1128","documentation":"Arity guard in karate.waitForPort(): both a host and a port are required to attempt the TCP connection poll. Fires when fewer than two arguments are given; pass host and port (optional timeout/poll interval may follow).","triggerScenarios":"Invoking karate.waitForPort('localhost') or karate.waitForPort() — any call supplying fewer than two arguments.","commonSituations":"Omitting the port when it was assumed to default (it does not); partial refactor of a call site; confusing this API with a single-object-argument style.","solutions":["Supply both arguments: karate.waitForPort('localhost', 8080)","Pass the port as a number (other types are converted but a Number is cleanest)","Check the call site passes variables that are both defined"],"exampleFix":"// before\nkarate.waitForPort(host);\n// after\nkarate.waitForPort(host, 9092);","handlingStrategy":"validation","validationCode":"// JS\nif (host == null || port == null) throw new Error('waitForPort needs host and port');\nkarate.waitForPort(host, port);","typeGuard":"// JS\nfunction canWaitForPort(h, p) { return typeof h === 'string' && h.length > 0 && typeof p === 'number'; }","tryCatchPattern":"if (arguments.length < 2) throw new Error('usage: karate.waitForPort(host, port)');","preventionTips":["Always supply both host and port explicitly — there is no port default","Pass the port as a Number","Check variables are defined before the call"],"tags":["argument-count","tcp","wait"],"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"}