karatelabs/karate · error · RuntimeException
Invalid match expression, no operator found: " + expression
Error message
Invalid match expression, no operator found: " + expression
What it means
The Gherkin parser's match-expression parser scans a 'match actual expected' expression looking for a recognized operator (==, contains, !contains, etc.). If the scan completes without finding any operator, a RuntimeException is thrown because the expression is structurally invalid and no comparison can be derived; the actual and expected sub-expressions cannot be split.
Solutions
- Add a valid operator (==, !=, contains, !contains, contains only, contains any, contains deep, within, etc.) to the expression
- Fix typos in the operator keyword
- Print/log the expression string to spot empty or mangled interpolation
Example fix
// before
match expression: "response foo { a: 1 }"
// after
match expression: "response == { a: 1 }" Defensive patterns
Strategy: validation
Validate before calling
// check the expression contains a known operator before parsing
static boolean hasMatchOperator(String expr) {
String[] ops = {"==", "!=", "contains", "!contains", "within", "!within"};
for (String op : ops) if (expr.contains(op)) return true;
return false;
} Try / catch
try {
MatchExpression me = parser.parseMatchExpression(text);
} catch (RuntimeException e) {
if (e.getMessage().startsWith("Invalid match expression")) {
throw new IllegalArgumentException("Fix operator in: " + text, e);
}
throw e;
} Prevention
- Always include a recognized operator in match expressions
- Lint .feature files for match syntax in CI
- Avoid building expressions via string concatenation of possibly-empty parts
- Unit-test template-generated match expressions
When it happens
Trigger: Passing a match expression string that lacks any recognized operator token to match-expression parsing in GherkinParser — e.g. 'response foo', a typo like 'containsx', or an expression where interpolation produced an empty operator.
Common situations: Typos in Karate match syntax in .feature files, copy-paste losing the '==' operator, or constructing match expressions programmatically with interpolated empty strings.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- invalid expression: " + text
- invalid shorthand initializer: only allowed in…
- invalid destructuring: rest element must be the last…
- invalid destructuring: rest element cannot have an…
- invalid
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/4ed087ba47bb9853.
Report an issue: GitHub.
Appendix: source
Thrown at karate-core/src/main/java/io/karatelabs/gherkin/GherkinParser.java:746
int tokenEnd = tokenStart + token.length;
if (operator == null) {
// Before operator - this is part of the actual expression
if (actualStart < 0) {
actualStart = tokenStart;
}
actualEnd = tokenEnd;
} else {
// After operator - this is part of the expected expression
if (expectedStart < 0) {
expectedStart = tokenStart;
}
expectedEnd = tokenEnd;
}
}
if (operator == null) {
throw new RuntimeException("Invalid match expression, no operator found: " + expression);
}
String actualExpr = actualStart >= 0 ? text.substring(actualStart, actualEnd).trim() : "";
String expectedExpr = expectedStart >= 0 ? text.substring(expectedStart, expectedEnd).trim() : "";
return new MatchExpression(each, actualExpr, operator, expectedExpr);
}
private static boolean isMatchOperator(String text) {
return text.equals("==") || text.equals("!=") ||
text.startsWith("contains") || text.equals("!contains") ||
text.equals("within") || text.equals("!within");
}
}
View on GitHub (pinned to a22eb90246)