karatelabs/karate · error · RuntimeException
waitForPort() needs host and port arguments
Error message
waitForPort() needs host and port arguments
What it means
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).
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
Example fix
// before karate.waitForPort(host); // after karate.waitForPort(host, 9092);
Defensive patterns
Strategy: validation
Validate before calling
// JS
if (host == null || port == null) throw new Error('waitForPort needs host and port');
karate.waitForPort(host, port); Type guard
// JS
function canWaitForPort(h, p) { return typeof h === 'string' && h.length > 0 && typeof p === 'number'; } Try / catch
if (arguments.length < 2) throw new Error('usage: karate.waitForPort(host, port)'); Prevention
- 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
When it happens
Trigger: Invoking karate.waitForPort('localhost') or karate.waitForPort() — any call supplying fewer than two arguments.
Common situations: 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.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- waitForHttp() needs a URL argument
- eval() needs one argument
- expect() needs at least one argument
- remove() needs two arguments: variable name and path
- setXml() needs at least two arguments: name and xml
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/7488da8efc49f989.
Report an issue: GitHub.
Appendix: source
Thrown at karate-core/src/main/java/io/karatelabs/core/KarateJsUtils.java:1110
try {
Thread.sleep(pollMs);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return false;
}
}
throw new RuntimeException("HTTP endpoint not available: " + url);
};
}
/**
* karate.waitForPort(host, port) - Wait for a TCP port to become available.
* Polls until a TCP connection can be established.
*/
static JavaInvokable waitForPort() {
return args -> {
if (args.length < 2) {
throw new RuntimeException("waitForPort() needs host and port arguments");
}
String host = args[0] + "";
int port;
if (args[1] instanceof Number) {
port = ((Number) args[1]).intValue();
} else {
port = Integer.parseInt(args[1].toString());
}
int timeoutMs = 30000;
int pollMs = 250;
if (args.length > 2 && args[2] instanceof Number) {
timeoutMs = ((Number) args[2]).intValue();
}
if (args.length > 3 && args[3] instanceof Number) {
pollMs = ((Number) args[3]).intValue();
}
long deadline = System.currentTimeMillis() + timeoutMs;
while (System.currentTimeMillis() < deadline) {View on GitHub (pinned to a22eb90246)