karatelabs/karate · warning
configure logging.mask.patterns
Error message
configure logging.mask.patterns[{}] invalid regex '{}': {} — skipped What it means
A `patterns` entry in a logging.mask config provided a `regex` string that `Pattern.compile` could not parse. The library skips that single rule and logs this warning naming the index, the bad regex, and the syntax error description, so the rest of the mask keeps working.
Solutions
- Fix the regex syntax; the warning includes `e.getDescription()` pointing at the offending part
- Paste the regex into a Java-regex-aware tester (java.util.Pattern syntax, not JS)
- Escape special characters properly, especially backslashes
- Split complex patterns into simpler ones to isolate the syntax error
Example fix
// before
karate.configure('logging.mask', { patterns: [{ regex: '[0-9{16}', replacement: '***' }] })
// after
karate.configure('logging.mask', { patterns: [{ regex: '[0-9]{16}', replacement: '***' }] }) Defensive patterns
Strategy: validation
Validate before calling
for (var p : patterns) {
try { java.util.regex.Pattern.compile((String) p.get("regex")); }
catch (java.util.regex.PatternSyntaxException e) {
throw new IllegalArgumentException("bad mask regex: " + e.getDescription());
}
} Try / catch
try { Pattern.compile(regexStr); } catch (PatternSyntaxException e) { /* fix regex: " + e.getDescription() */ } Prevention
- Test regexes with Java Pattern syntax, not JavaScript regex
- Escape backslashes correctly in string literals
- Compile patterns once in a unit test to catch typos early
When it happens
Trigger: `karate.configure('logging.mask', { patterns: [{ regex: '[a-z+', replacement: 'x' }] })` — any syntactically invalid Java regex (unclosed bracket/paren, bad quantifier, dangling escape) in a patterns entry.
Common situations: Hand-written regex typos; regexes copied from JavaScript/PCRE with constructs Java's `Pattern` rejects (e.g. lookbehind of variable length, `\p{...}` script names); dynamically generated regexes from untrusted string concatenation.
Related errors
- configure logging.mask.patterns
- configure logging.mask: no usable rules — set at least one…
- configure logging.mask: unknown key
- configure ' ' is deprecated; use 'configure logging = }
- configure 'logging' expects a map, got
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/f6ac5d770e82ed28.
Report an issue: GitHub.
Appendix: source
Thrown at karate-core/src/main/java/io/karatelabs/output/LogMask.java:126
if (map.get("patterns") instanceof List<?> list) {
int idx = 0;
for (Object item : list) {
if (item instanceof Map<?, ?> pm) {
Object regex = pm.get("regex");
if (regex == null) {
logger.warn("configure logging.mask.patterns[{}] missing 'regex' — skipped", idx);
idx++;
continue;
}
Object rep = pm.get("replacement");
String repStr = rep == null ? replacement : rep.toString();
try {
patternRules.add(new PatternRule(Pattern.compile(regex.toString()), repStr));
} catch (PatternSyntaxException e) {
// Skip rather than fail-fast — a typo in one rule shouldn't blow up
// the whole config-js eval. The warn names the entry so the user
// can find it. Other rules in the same mask still apply.
logger.warn("configure logging.mask.patterns[{}] invalid regex '{}': {} — skipped",
idx, regex, e.getDescription());
}
}
idx++;
}
}
JavaCallable enableForUri = map.get("enableForUri") instanceof JavaCallable c ? c : null;
if (headers.isEmpty() && jsonPaths.isEmpty() && patternRules.isEmpty()) {
// User provided a mask map but every rule list is empty / invalid. Without this
// warn the mask silently does nothing, which is hard to debug.
logger.warn("configure logging.mask: no usable rules — set at least one of "
+ "headers / jsonPaths / patterns. mask is OFF.");
return null;
}
return new LogMask(headers, jsonPaths, patternRules, replacement, enableForUri);
}
/**View on GitHub (pinned to a22eb90246)