karatelabs/karate · error · RuntimeException
missing argument for pathMatches()
Error message
missing argument for pathMatches()
What it means
The request.pathMatches() invokable requires one argument (a URI-template pattern) to test against the request path. With zero arguments it throws RuntimeException 'missing argument for pathMatches()'.
Solutions
- Pass the path pattern: request.pathMatches('/api/{version}/items')
- Verify the pattern variable is non-empty before the call
- Use the plain path accessor if you only need the path without matching
Example fix
// before
var m = request.pathMatches();
// after
var m = request.pathMatches('/users/{id}'); Defensive patterns
Strategy: type-guard
Validate before calling
if (pattern == null || pattern.isEmpty()) throw new IllegalArgumentException("path pattern required"); Type guard
function requireArg(pattern, args) { if (args == null || args.length === 0) throw new Error('missing argument for pathMatches()'); return pattern; } Try / catch
try { var m = request.pathMatches('/users/{id}'); } catch (RuntimeException e) { /* fix call site: pattern missing */ } Prevention
- Always pass the URI-template pattern to pathMatches()
- Validate pattern variables are non-empty before interpolation
- Keep patterns in named constants to avoid accidental omission in route scripts
When it happens
Trigger: Calling request.pathMatches() with no arguments instead of request.pathMatches('/users/{id}').
Common situations: Dropped pattern argument in mock/route scripts, empty variable interpolated as the pattern, confusion with a no-arg path getter.
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
- missing argument for header()
- missing argument for headerValues()
- missing argument for param()
- missing argument for paramInt()
- missing argument for paramJson()
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/3bb089d9c367c467.
Report an issue: GitHub.
Appendix: source
Thrown at karate-core/src/main/java/io/karatelabs/http/HttpRequest.java:665
};
}
private JavaInvokable headerValues() {
return args -> {
if (args.length > 0) {
return getHeaderValues(args[0] + "");
} else {
throw new RuntimeException("missing argument for headerValues()");
}
};
}
private JavaInvokable pathMatches() {
return args -> {
if (args.length > 0) {
return pathMatches(args[0] + "");
} else {
throw new RuntimeException("missing argument for pathMatches()");
}
};
}
private JavaInvokable multiPart() {
return args -> {
if (args.length > 0) {
return getMultiPart(args[0] + "");
} else {
throw new RuntimeException("missing argument for multiPart()");
}
};
}
private JavaInvokable file() {
return args -> {
if (args.length > 0) {
return getFile(args[0] + "");View on GitHub (pinned to a22eb90246)